
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Deployment 的实现原理 · 这是程序员吗</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="xishengcai">
        
        
    
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-toggle-chapters/toggle.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-plus/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-disqus/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-prism/prism-base16-ateliersulphurpool.light.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-advanced-emoji/emoji-website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-anchors/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-emphasize/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-katex/katex.min.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.css">
                
            
                
                <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-sectionx/sectionx.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-donate/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-local-video/video-js.min.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-terminal/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-alerts/style.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-versions-select/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    


    

        
    
    
    
    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="K8s源码/" />
    
    
    <link rel="prev" href="CAK.html" />
    

    
    <link rel="stylesheet" href="../../gitbook/gitbook-plugin-chart/c3/c3.min.css">
    <script src="../../gitbook/gitbook-plugin-chart/c3/d3.min.js"></script>
    <script src="../../gitbook/gitbook-plugin-chart/c3/c3.min.js"></script>
    

    <script src="../../gitbook/gitbook-plugin-graph/d3.min.js"></script>
    <script src="../../gitbook/gitbook-plugin-graph/function-plot.js"></script>    

    
        <link rel="shortcut icon" href='../../favicon.ico' type="image/x-icon">
    
    
        <link rel="bookmark" href='../../favicon.ico' type="image/x-icon">
    
    
    

    <style>
    @media only screen and (max-width: 640px) {
        .book-header .hidden-mobile {
            display: none;
        }
    }
    </style>
    <script>
        window["gitbook-plugin-github-buttons"] = {"repo":"xishengcai/xisheng.blog","types":["star"],"size":"small"};
    </script>

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="https://xisheng.vip" target="_blank" class="custom-link">Home</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        <li class="header">Blog</li>
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                        <b>1.1.</b>
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../algorithm/">
            
                <a href="../algorithm/">
            
                    
                        <b>1.2.</b>
                    
                    Algorithm
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../algorithm/heap.html">
            
                <a href="../algorithm/heap.html">
            
                    
                        <b>1.2.1.</b>
                    
                    Heap
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../algorithm/readme.html">
            
                <a href="../algorithm/readme.html">
            
                    
                        <b>1.2.2.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../angular/">
            
                <a href="../angular/">
            
                    
                        <b>1.3.</b>
                    
                    Angular
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../angular/1-start.html">
            
                <a href="../angular/1-start.html">
            
                    
                        <b>1.3.1.</b>
                    
                    Start
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../angular/2-component.html">
            
                <a href="../angular/2-component.html">
            
                    
                        <b>1.3.2.</b>
                    
                    Component
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../angular/3-form.html">
            
                <a href="../angular/3-form.html">
            
                    
                        <b>1.3.3.</b>
                    
                    Form
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../angular/readme.html">
            
                <a href="../angular/readme.html">
            
                    
                        <b>1.3.4.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../database/">
            
                <a href="../database/">
            
                    
                        <b>1.4.</b>
                    
                    Database
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../database/mongodb.html">
            
                <a href="../database/mongodb.html">
            
                    
                        <b>1.4.1.</b>
                    
                    Mongodb
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../database/readme.html">
            
                <a href="../database/readme.html">
            
                    
                        <b>1.4.2.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../docker/">
            
                <a href="../docker/">
            
                    
                        <b>1.5.</b>
                    
                    Docker
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../docker/CentOS.html">
            
                <a href="../docker/CentOS.html">
            
                    
                        <b>1.5.1.</b>
                    
                    CentOS
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../docker/install.html">
            
                <a href="../docker/install.html">
            
                    
                        <b>1.5.2.</b>
                    
                    Install
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../docker/readme.html">
            
                <a href="../docker/readme.html">
            
                    
                        <b>1.5.3.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../docker/官方shell.html">
            
                <a href="../docker/官方shell.html">
            
                    
                        <b>1.5.4.</b>
                    
                    官方Shell
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../golang/">
            
                <a href="../golang/">
            
                    
                        <b>1.6.</b>
                    
                    Golang
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../golang/aop.html">
            
                <a href="../golang/aop.html">
            
                    
                        <b>1.6.1.</b>
                    
                    Aop
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../golang/base/">
            
                <a href="../golang/base/">
            
                    
                        <b>1.6.2.</b>
                    
                    Base
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.2.1" data-path="../golang/base/copy.html">
            
                <a href="../golang/base/copy.html">
            
                    
                        <b>1.6.2.1.</b>
                    
                    Copy
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2.2" data-path="../golang/base/new_and_make.html">
            
                <a href="../golang/base/new_and_make.html">
            
                    
                        <b>1.6.2.2.</b>
                    
                    New And Make
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2.3" data-path="../golang/base/readme.html">
            
                <a href="../golang/base/readme.html">
            
                    
                        <b>1.6.2.3.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2.4" data-path="../golang/base/reflect.html">
            
                <a href="../golang/base/reflect.html">
            
                    
                        <b>1.6.2.4.</b>
                    
                    Reflect
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2.5" data-path="../golang/base/string.html">
            
                <a href="../golang/base/string.html">
            
                    
                        <b>1.6.2.5.</b>
                    
                    String
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2.6" data-path="../golang/base/tag.html">
            
                <a href="../golang/base/tag.html">
            
                    
                        <b>1.6.2.6.</b>
                    
                    Tag
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../golang/clouser.html">
            
                <a href="../golang/clouser.html">
            
                    
                        <b>1.6.3.</b>
                    
                    Clouser
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../golang/err 优雅处理.html">
            
                <a href="../golang/err 优雅处理.html">
            
                    
                        <b>1.6.4.</b>
                    
                    Err 优雅处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../golang/go module 2.html">
            
                <a href="../golang/go module 2.html">
            
                    
                        <b>1.6.5.</b>
                    
                    Go Module 2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="../golang/go_mod.html">
            
                <a href="../golang/go_mod.html">
            
                    
                        <b>1.6.6.</b>
                    
                    Go Mod
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="../golang/gocraftwork.html">
            
                <a href="../golang/gocraftwork.html">
            
                    
                        <b>1.6.7.</b>
                    
                    Gocraftwork
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.8" data-path="../golang/oauth.html">
            
                <a href="../golang/oauth.html">
            
                    
                        <b>1.6.8.</b>
                    
                    Oauth
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.9" data-path="../golang/readme.html">
            
                <a href="../golang/readme.html">
            
                    
                        <b>1.6.9.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.10" data-path="../golang/swagger.html">
            
                <a href="../golang/swagger.html">
            
                    
                        <b>1.6.10.</b>
                    
                    Swagger
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.11" data-path="../golang/tls.html">
            
                <a href="../golang/tls.html">
            
                    
                        <b>1.6.11.</b>
                    
                    Tls
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.12" >
            
                <span>
            
                    
                        <b>1.6.12.</b>
                    
                    代码走读
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.12.1" data-path="../golang/代码走读/2020.5.26.html">
            
                <a href="../golang/代码走读/2020.5.26.html">
            
                    
                        <b>1.6.12.1.</b>
                    
                    2020.5.26
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6.13" data-path="../golang/任务队列/">
            
                <a href="../golang/任务队列/">
            
                    
                        <b>1.6.13.</b>
                    
                    任务队列
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.13.1" data-path="../golang/任务队列/gocraft-worker.html">
            
                <a href="../golang/任务队列/gocraft-worker.html">
            
                    
                        <b>1.6.13.1.</b>
                    
                    Gocraft Worker
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.13.2" data-path="../golang/任务队列/readme.html">
            
                <a href="../golang/任务队列/readme.html">
            
                    
                        <b>1.6.13.2.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6.14" data-path="../golang/参数校验.html">
            
                <a href="../golang/参数校验.html">
            
                    
                        <b>1.6.14.</b>
                    
                    参数校验
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../istio/">
            
                <a href="../istio/">
            
                    
                        <b>1.7.</b>
                    
                    Istio
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../istio/readme.html">
            
                <a href="../istio/readme.html">
            
                    
                        <b>1.7.1.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../istio/virtualservice.html">
            
                <a href="../istio/virtualservice.html">
            
                    
                        <b>1.7.2.</b>
                    
                    Virtualservice
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" >
            
                <span>
            
                    
                        <b>1.8.</b>
                    
                    Java
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../java/jvm.html">
            
                <a href="../java/jvm.html">
            
                    
                        <b>1.8.1.</b>
                    
                    Jvm
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../java/typescript.html">
            
                <a href="../java/typescript.html">
            
                    
                        <b>1.8.2.</b>
                    
                    Typescript
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="./">
            
                <a href="./">
            
                    
                        <b>1.9.</b>
                    
                    Kubernetes
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="APIService.html">
            
                <a href="APIService.html">
            
                    
                        <b>1.9.1.</b>
                    
                    APIService
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="CAK.html">
            
                <a href="CAK.html">
            
                    
                        <b>1.9.2.</b>
                    
                    CAK
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.9.3" data-path="Deployment 的实现原理.html">
            
                <a href="Deployment 的实现原理.html">
            
                    
                        <b>1.9.3.</b>
                    
                    Deployment 的实现原理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4" data-path="K8s源码/">
            
                <a href="K8s源码/">
            
                    
                        <b>1.9.4.</b>
                    
                    K8s源码
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.4.1" data-path="K8s源码/calico 源码分析.html">
            
                <a href="K8s源码/calico 源码分析.html">
            
                    
                        <b>1.9.4.1.</b>
                    
                    Calico 源码分析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4.2" data-path="K8s源码/garbage collector controller 源码分析.html">
            
                <a href="K8s源码/garbage collector controller 源码分析.html">
            
                    
                        <b>1.9.4.2.</b>
                    
                    Garbage Collector Controller 源码分析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4.3" data-path="K8s源码/job.html">
            
                <a href="K8s源码/job.html">
            
                    
                        <b>1.9.4.3.</b>
                    
                    Job
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4.4" data-path="K8s源码/kube-proxy-iptables.html">
            
                <a href="K8s源码/kube-proxy-iptables.html">
            
                    
                        <b>1.9.4.4.</b>
                    
                    Kube Proxy Iptables
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4.5" data-path="K8s源码/kube-proxy-ipvs.html">
            
                <a href="K8s源码/kube-proxy-ipvs.html">
            
                    
                        <b>1.9.4.5.</b>
                    
                    Kube Proxy Ipvs
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4.6" data-path="K8s源码/kube-proxy.html">
            
                <a href="K8s源码/kube-proxy.html">
            
                    
                        <b>1.9.4.6.</b>
                    
                    Kube Proxy
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4.7" data-path="K8s源码/kubectl-exec.html">
            
                <a href="K8s源码/kubectl-exec.html">
            
                    
                        <b>1.9.4.7.</b>
                    
                    Kubectl Exec
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4.8" data-path="K8s源码/kubectl源码阅读1.html">
            
                <a href="K8s源码/kubectl源码阅读1.html">
            
                    
                        <b>1.9.4.8.</b>
                    
                    Kubectl源码阅读1
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4.9" data-path="K8s源码/kubectl源码阅读2.html">
            
                <a href="K8s源码/kubectl源码阅读2.html">
            
                    
                        <b>1.9.4.9.</b>
                    
                    Kubectl源码阅读2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4.10" data-path="K8s源码/readme.html">
            
                <a href="K8s源码/readme.html">
            
                    
                        <b>1.9.4.10.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4.11" data-path="K8s源码/schedule.html">
            
                <a href="K8s源码/schedule.html">
            
                    
                        <b>1.9.4.11.</b>
                    
                    Schedule
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4.12" data-path="K8s源码/scheme.html">
            
                <a href="K8s源码/scheme.html">
            
                    
                        <b>1.9.4.12.</b>
                    
                    Scheme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4.13" data-path="K8s源码/调度队列.html">
            
                <a href="K8s源码/调度队列.html">
            
                    
                        <b>1.9.4.13.</b>
                    
                    调度队列
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9.5" data-path="Karmada.html">
            
                <a href="Karmada.html">
            
                    
                        <b>1.9.5.</b>
                    
                    Karmada
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.6" data-path="Pixie.html">
            
                <a href="Pixie.html">
            
                    
                        <b>1.9.6.</b>
                    
                    Pixie
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.7" data-path="admission access.html">
            
                <a href="admission access.html">
            
                    
                        <b>1.9.7.</b>
                    
                    Admission Access
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.8" data-path="ccm.html">
            
                <a href="ccm.html">
            
                    
                        <b>1.9.8.</b>
                    
                    Ccm
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.9" data-path="client-go.html">
            
                <a href="client-go.html">
            
                    
                        <b>1.9.9.</b>
                    
                    Client Go
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.10" data-path="command.html">
            
                <a href="command.html">
            
                    
                        <b>1.9.10.</b>
                    
                    Command
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.11" data-path="controller.html">
            
                <a href="controller.html">
            
                    
                        <b>1.9.11.</b>
                    
                    Controller
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.12" data-path="copy docker config.html">
            
                <a href="copy docker config.html">
            
                    
                        <b>1.9.12.</b>
                    
                    Copy Docker Config
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.13" data-path="etcd-operation.html">
            
                <a href="etcd-operation.html">
            
                    
                        <b>1.9.13.</b>
                    
                    Etcd Operation
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.14" data-path="gc.html">
            
                <a href="gc.html">
            
                    
                        <b>1.9.14.</b>
                    
                    Gc
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.15" data-path="helm chart.html">
            
                <a href="helm chart.html">
            
                    
                        <b>1.9.15.</b>
                    
                    Helm Chart
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.16" data-path="helm.html">
            
                <a href="helm.html">
            
                    
                        <b>1.9.16.</b>
                    
                    Helm
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.17" >
            
                <span>
            
                    
                        <b>1.9.17.</b>
                    
                    Helm
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.17.1" data-path="helm/charts.html">
            
                <a href="helm/charts.html">
            
                    
                        <b>1.9.17.1.</b>
                    
                    Charts
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.17.2" data-path="helm/helm 钩子函数.html">
            
                <a href="helm/helm 钩子函数.html">
            
                    
                        <b>1.9.17.2.</b>
                    
                    Helm 钩子函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.17.3" data-path="helm/helm-operator.html">
            
                <a href="helm/helm-operator.html">
            
                    
                        <b>1.9.17.3.</b>
                    
                    Helm Operator
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.17.4" data-path="helm/文档查询.html">
            
                <a href="helm/文档查询.html">
            
                    
                        <b>1.9.17.4.</b>
                    
                    文档查询
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.17.5" data-path="helm/语法.html">
            
                <a href="helm/语法.html">
            
                    
                        <b>1.9.17.5.</b>
                    
                    语法
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9.18" data-path="install.html">
            
                <a href="install.html">
            
                    
                        <b>1.9.18.</b>
                    
                    Install
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.19" data-path="istio-inject.html">
            
                <a href="istio-inject.html">
            
                    
                        <b>1.9.19.</b>
                    
                    Istio Inject
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.20" >
            
                <span>
            
                    
                        <b>1.9.20.</b>
                    
                    KubeEdge
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.21" data-path="kuber-apiserver-flag.html">
            
                <a href="kuber-apiserver-flag.html">
            
                    
                        <b>1.9.21.</b>
                    
                    Kuber Apiserver Flag
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.22" data-path="kubernetes-client.html">
            
                <a href="kubernetes-client.html">
            
                    
                        <b>1.9.22.</b>
                    
                    Kubernetes Client
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.23" data-path="kubernetes灾备.html">
            
                <a href="kubernetes灾备.html">
            
                    
                        <b>1.9.23.</b>
                    
                    Kubernetes灾备
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.24" data-path="kubesphere/">
            
                <a href="kubesphere/">
            
                    
                        <b>1.9.24.</b>
                    
                    Kubesphere
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.24.1" data-path="kubesphere/helm.html">
            
                <a href="kubesphere/helm.html">
            
                    
                        <b>1.9.24.1.</b>
                    
                    Helm
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.24.2" data-path="kubesphere/readme.html">
            
                <a href="kubesphere/readme.html">
            
                    
                        <b>1.9.24.2.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9.25" data-path="kubevela/">
            
                <a href="kubevela/">
            
                    
                        <b>1.9.25.</b>
                    
                    Kubevela
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.25.1" data-path="kubevela/KubeVela 功能.html">
            
                <a href="kubevela/KubeVela 功能.html">
            
                    
                        <b>1.9.25.1.</b>
                    
                    KubeVela 功能
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.25.2" data-path="kubevela/cue.html">
            
                <a href="kubevela/cue.html">
            
                    
                        <b>1.9.25.2.</b>
                    
                    Cue
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.25.3" data-path="kubevela/oam.html">
            
                <a href="kubevela/oam.html">
            
                    
                        <b>1.9.25.3.</b>
                    
                    Oam
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.25.4" data-path="kubevela/readme.html">
            
                <a href="kubevela/readme.html">
            
                    
                        <b>1.9.25.4.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.25.5" data-path="kubevela/rollout design.html">
            
                <a href="kubevela/rollout design.html">
            
                    
                        <b>1.9.25.5.</b>
                    
                    Rollout Design
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.25.6" data-path="kubevela/vela run.html">
            
                <a href="kubevela/vela run.html">
            
                    
                        <b>1.9.25.6.</b>
                    
                    Vela Run
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.25.7" data-path="kubevela/vela up.html">
            
                <a href="kubevela/vela up.html">
            
                    
                        <b>1.9.25.7.</b>
                    
                    Vela Up
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.25.8" data-path="kubevela/vela-cluster.html">
            
                <a href="kubevela/vela-cluster.html">
            
                    
                        <b>1.9.25.8.</b>
                    
                    Vela Cluster
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.25.9" data-path="kubevela/vela-helm.html">
            
                <a href="kubevela/vela-helm.html">
            
                    
                        <b>1.9.25.9.</b>
                    
                    Vela Helm
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.25.10" data-path="kubevela/vela-pk-oam.html">
            
                <a href="kubevela/vela-pk-oam.html">
            
                    
                        <b>1.9.25.10.</b>
                    
                    Vela Pk Oam
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9.26" data-path="mk-cert.html">
            
                <a href="mk-cert.html">
            
                    
                        <b>1.9.26.</b>
                    
                    Mk Cert
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.27" data-path="open_swagger-ui.html">
            
                <a href="open_swagger-ui.html">
            
                    
                        <b>1.9.27.</b>
                    
                    Open Swagger Ui
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.28" data-path="readme.html">
            
                <a href="readme.html">
            
                    
                        <b>1.9.28.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.29" data-path="task/">
            
                <a href="task/">
            
                    
                        <b>1.9.29.</b>
                    
                    Task
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.29.1" data-path="task/HPA.html">
            
                <a href="task/HPA.html">
            
                    
                        <b>1.9.29.1.</b>
                    
                    HPA
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.29.2" data-path="task/kubectl patch.html">
            
                <a href="task/kubectl patch.html">
            
                    
                        <b>1.9.29.2.</b>
                    
                    Kubectl Patch
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.29.3" data-path="task/pod 信息注入.html">
            
                <a href="task/pod 信息注入.html">
            
                    
                        <b>1.9.29.3.</b>
                    
                    Pod 信息注入
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.29.4" data-path="task/pod 垂直扩缩容.html">
            
                <a href="task/pod 垂直扩缩容.html">
            
                    
                        <b>1.9.29.4.</b>
                    
                    Pod 垂直扩缩容
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.29.5" data-path="task/readme.html">
            
                <a href="task/readme.html">
            
                    
                        <b>1.9.29.5.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.29.6" data-path="task/server-side-apply.html">
            
                <a href="task/server-side-apply.html">
            
                    
                        <b>1.9.29.6.</b>
                    
                    Server Side Apply
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.29.7" data-path="task/准入控制.html">
            
                <a href="task/准入控制.html">
            
                    
                        <b>1.9.29.7.</b>
                    
                    准入控制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.29.8" data-path="task/聚合api.html">
            
                <a href="task/聚合api.html">
            
                    
                        <b>1.9.29.8.</b>
                    
                    聚合Api
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.29.9" data-path="task/资源预留配置.html">
            
                <a href="task/资源预留配置.html">
            
                    
                        <b>1.9.29.9.</b>
                    
                    资源预留配置
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9.30" data-path="webhook.html">
            
                <a href="webhook.html">
            
                    
                        <b>1.9.30.</b>
                    
                    Webhook
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.31" data-path="一致性认证.html">
            
                <a href="一致性认证.html">
            
                    
                        <b>1.9.31.</b>
                    
                    一致性认证
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.32" data-path="专利名词.html">
            
                <a href="专利名词.html">
            
                    
                        <b>1.9.32.</b>
                    
                    专利名词
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.33" data-path="删除namespace.html">
            
                <a href="删除namespace.html">
            
                    
                        <b>1.9.33.</b>
                    
                    删除Namespace
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.34" data-path="简化多集群.html">
            
                <a href="简化多集群.html">
            
                    
                        <b>1.9.34.</b>
                    
                    简化多集群
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.35" data-path="网络插件/">
            
                <a href="网络插件/">
            
                    
                        <b>1.9.35.</b>
                    
                    网络插件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.35.1" data-path="网络插件/calico.html">
            
                <a href="网络插件/calico.html">
            
                    
                        <b>1.9.35.1.</b>
                    
                    Calico
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.35.2" data-path="网络插件/cilium.html">
            
                <a href="网络插件/cilium.html">
            
                    
                        <b>1.9.35.2.</b>
                    
                    Cilium
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.35.3" data-path="网络插件/ebpf.html">
            
                <a href="网络插件/ebpf.html">
            
                    
                        <b>1.9.35.3.</b>
                    
                    Ebpf
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.35.4" data-path="网络插件/readme.html">
            
                <a href="网络插件/readme.html">
            
                    
                        <b>1.9.35.4.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9.36" data-path="镜像/">
            
                <a href="镜像/">
            
                    
                        <b>1.9.36.</b>
                    
                    镜像
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.36.1" data-path="镜像/Containerd Stargz Snapshotter.html">
            
                <a href="镜像/Containerd Stargz Snapshotter.html">
            
                    
                        <b>1.9.36.1.</b>
                    
                    Containerd Stargz Snapshotter
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.36.2" data-path="镜像/OCI.html">
            
                <a href="镜像/OCI.html">
            
                    
                        <b>1.9.36.2.</b>
                    
                    OCI
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.36.3" data-path="镜像/harbor/">
            
                <a href="镜像/harbor/">
            
                    
                        <b>1.9.36.3.</b>
                    
                    Harbor
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.36.3.1" data-path="镜像/harbor/readme.html">
            
                <a href="镜像/harbor/readme.html">
            
                    
                        <b>1.9.36.3.1.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9.36.4" data-path="镜像/readme.html">
            
                <a href="镜像/readme.html">
            
                    
                        <b>1.9.36.4.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.36.5" data-path="镜像/自动构建镜像.html">
            
                <a href="镜像/自动构建镜像.html">
            
                    
                        <b>1.9.36.5.</b>
                    
                    自动构建镜像
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.36.6" data-path="镜像/镜像加速方案.html">
            
                <a href="镜像/镜像加速方案.html">
            
                    
                        <b>1.9.36.6.</b>
                    
                    镜像加速方案
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.36.7" data-path="镜像/镜像延迟加载技术解析.html">
            
                <a href="镜像/镜像延迟加载技术解析.html">
            
                    
                        <b>1.9.36.7.</b>
                    
                    镜像延迟加载技术解析
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../math/">
            
                <a href="../math/">
            
                    
                        <b>1.10.</b>
                    
                    Math
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../math/readme.html">
            
                <a href="../math/readme.html">
            
                    
                        <b>1.10.1.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="../math/泊松分布.html">
            
                <a href="../math/泊松分布.html">
            
                    
                        <b>1.10.2.</b>
                    
                    泊松分布
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../效率/">
            
                <a href="../效率/">
            
                    
                        <b>1.11.</b>
                    
                    效率
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../效率/cat.html">
            
                <a href="../效率/cat.html">
            
                    
                        <b>1.11.1.</b>
                    
                    Cat
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2" data-path="../效率/docker volume clean.html">
            
                <a href="../效率/docker volume clean.html">
            
                    
                        <b>1.11.2.</b>
                    
                    Docker Volume Clean
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.3" data-path="../效率/git book.html">
            
                <a href="../效率/git book.html">
            
                    
                        <b>1.11.3.</b>
                    
                    Git Book
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.4" data-path="../效率/git.html">
            
                <a href="../效率/git.html">
            
                    
                        <b>1.11.4.</b>
                    
                    Git
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.5" data-path="../效率/linux command.html">
            
                <a href="../效率/linux command.html">
            
                    
                        <b>1.11.5.</b>
                    
                    Linux Command
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.6" data-path="../效率/linux 内核.html">
            
                <a href="../效率/linux 内核.html">
            
                    
                        <b>1.11.6.</b>
                    
                    Linux 内核
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.7" data-path="../效率/macos path.html">
            
                <a href="../效率/macos path.html">
            
                    
                        <b>1.11.7.</b>
                    
                    Macos Path
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.8" data-path="../效率/nfs.html">
            
                <a href="../效率/nfs.html">
            
                    
                        <b>1.11.8.</b>
                    
                    Nfs
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.9" data-path="../效率/nginx.html">
            
                <a href="../效率/nginx.html">
            
                    
                        <b>1.11.9.</b>
                    
                    Nginx
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.10" data-path="../效率/nginx2.html">
            
                <a href="../效率/nginx2.html">
            
                    
                        <b>1.11.10.</b>
                    
                    Nginx2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.11" data-path="../效率/oauth2.html">
            
                <a href="../效率/oauth2.html">
            
                    
                        <b>1.11.11.</b>
                    
                    Oauth2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.12" data-path="../效率/ovftool.html">
            
                <a href="../效率/ovftool.html">
            
                    
                        <b>1.11.12.</b>
                    
                    Ovftool
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.13" data-path="../效率/readme.html">
            
                <a href="../效率/readme.html">
            
                    
                        <b>1.11.13.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.14" data-path="../效率/sed.html">
            
                <a href="../效率/sed.html">
            
                    
                        <b>1.11.14.</b>
                    
                    Sed
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.15" data-path="../效率/shell_judge.html">
            
                <a href="../效率/shell_judge.html">
            
                    
                        <b>1.11.15.</b>
                    
                    Shell Judge
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.16" data-path="../效率/sshpass.html">
            
                <a href="../效率/sshpass.html">
            
                    
                        <b>1.11.16.</b>
                    
                    Sshpass
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.17" data-path="../效率/telepresence.html">
            
                <a href="../效率/telepresence.html">
            
                    
                        <b>1.11.17.</b>
                    
                    Telepresence
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.18" data-path="../效率/typora.html">
            
                <a href="../效率/typora.html">
            
                    
                        <b>1.11.18.</b>
                    
                    Typora
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.19" data-path="../效率/url encode.html">
            
                <a href="../效率/url encode.html">
            
                    
                        <b>1.11.19.</b>
                    
                    Url Encode
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.20" data-path="../效率/vim.html">
            
                <a href="../效率/vim.html">
            
                    
                        <b>1.11.20.</b>
                    
                    Vim
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.21" data-path="../效率/yum.html">
            
                <a href="../效率/yum.html">
            
                    
                        <b>1.11.21.</b>
                    
                    Yum
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.22" data-path="../效率/内网穿透.html">
            
                <a href="../效率/内网穿透.html">
            
                    
                        <b>1.11.22.</b>
                    
                    内网穿透
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.23" data-path="../效率/科学上网.html">
            
                <a href="../效率/科学上网.html">
            
                    
                        <b>1.11.23.</b>
                    
                    科学上网
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.24" data-path="../效率/证书制作.html">
            
                <a href="../效率/证书制作.html">
            
                    
                        <b>1.11.24.</b>
                    
                    证书制作
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" >
            
                <span>
            
                    
                        <b>1.12.</b>
                    
                    杂谈
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.12.1" data-path="../杂谈/论好文章和烂文章.html">
            
                <a href="../杂谈/论好文章和烂文章.html">
            
                    
                        <b>1.12.1.</b>
                    
                    论好文章和烂文章
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../测试/">
            
                <a href="../测试/">
            
                    
                        <b>1.13.</b>
                    
                    测试
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.13.1" data-path="../测试/ginkgo/">
            
                <a href="../测试/ginkgo/">
            
                    
                        <b>1.13.1.</b>
                    
                    Ginkgo
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.13.1.1" data-path="../测试/ginkgo/ginkgo.html">
            
                <a href="../测试/ginkgo/ginkgo.html">
            
                    
                        <b>1.13.1.1.</b>
                    
                    Ginkgo
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.1.2" data-path="../测试/ginkgo/ginkgo_cmd.html">
            
                <a href="../测试/ginkgo/ginkgo_cmd.html">
            
                    
                        <b>1.13.1.2.</b>
                    
                    Ginkgo Cmd
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.1.3" data-path="../测试/ginkgo/readme.html">
            
                <a href="../测试/ginkgo/readme.html">
            
                    
                        <b>1.13.1.3.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.13.2" data-path="../测试/golang-test.html">
            
                <a href="../测试/golang-test.html">
            
                    
                        <b>1.13.2.</b>
                    
                    Golang Test
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.3" data-path="../测试/http测试.html">
            
                <a href="../测试/http测试.html">
            
                    
                        <b>1.13.3.</b>
                    
                    Http测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.4" data-path="../测试/readme.html">
            
                <a href="../测试/readme.html">
            
                    
                        <b>1.13.4.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.5" data-path="../测试/其他功能.html">
            
                <a href="../测试/其他功能.html">
            
                    
                        <b>1.13.5.</b>
                    
                    其他功能
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.6" data-path="../测试/单元测试.html">
            
                <a href="../测试/单元测试.html">
            
                    
                        <b>1.13.6.</b>
                    
                    单元测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.7" data-path="../测试/单元测试2.html">
            
                <a href="../测试/单元测试2.html">
            
                    
                        <b>1.13.7.</b>
                    
                    单元测试2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.8" data-path="../测试/基准测试.html">
            
                <a href="../测试/基准测试.html">
            
                    
                        <b>1.13.8.</b>
                    
                    基准测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.9" data-path="../测试/子测试与子基准测试.html">
            
                <a href="../测试/子测试与子基准测试.html">
            
                    
                        <b>1.13.9.</b>
                    
                    子测试与子基准测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.10" data-path="../测试/并行测试.html">
            
                <a href="../测试/并行测试.html">
            
                    
                        <b>1.13.10.</b>
                    
                    并行测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.11" data-path="../测试/质量检查/">
            
                <a href="../测试/质量检查/">
            
                    
                        <b>1.13.11.</b>
                    
                    质量检查
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.13.11.1" data-path="../测试/质量检查/Sonar.html">
            
                <a href="../测试/质量检查/Sonar.html">
            
                    
                        <b>1.13.11.1.</b>
                    
                    Sonar
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.11.2" data-path="../测试/质量检查/go_lint.html">
            
                <a href="../测试/质量检查/go_lint.html">
            
                    
                        <b>1.13.11.2.</b>
                    
                    Go Lint
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.11.3" data-path="../测试/质量检查/readme.html">
            
                <a href="../测试/质量检查/readme.html">
            
                    
                        <b>1.13.11.3.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="../规范/">
            
                <a href="../规范/">
            
                    
                        <b>1.14.</b>
                    
                    规范
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.14.1" data-path="../规范/CodeReviewComments.html">
            
                <a href="../规范/CodeReviewComments.html">
            
                    
                        <b>1.14.1.</b>
                    
                    CodeReviewComments
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.2" data-path="../规范/git规范.html">
            
                <a href="../规范/git规范.html">
            
                    
                        <b>1.14.2.</b>
                    
                    Git规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.3" data-path="../规范/golang 代码规范.html">
            
                <a href="../规范/golang 代码规范.html">
            
                    
                        <b>1.14.3.</b>
                    
                    Golang 代码规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.4" data-path="../规范/readme.html">
            
                <a href="../规范/readme.html">
            
                    
                        <b>1.14.4.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.5" data-path="../规范/代码走读.html">
            
                <a href="../规范/代码走读.html">
            
                    
                        <b>1.14.5.</b>
                    
                    代码走读
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="../设计模式/">
            
                <a href="../设计模式/">
            
                    
                        <b>1.15.</b>
                    
                    设计模式
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.15.1" data-path="../设计模式/readme.html">
            
                <a href="../设计模式/readme.html">
            
                    
                        <b>1.15.1.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.2" data-path="../设计模式/创建模型/">
            
                <a href="../设计模式/创建模型/">
            
                    
                        <b>1.15.2.</b>
                    
                    创建模型
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.15.2.1" data-path="../设计模式/创建模型/readme.html">
            
                <a href="../设计模式/创建模型/readme.html">
            
                    
                        <b>1.15.2.1.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.2.2" data-path="../设计模式/创建模型/创建者模型.html">
            
                <a href="../设计模式/创建模型/创建者模型.html">
            
                    
                        <b>1.15.2.2.</b>
                    
                    创建者模型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.2.3" data-path="../设计模式/创建模型/单例模式.html">
            
                <a href="../设计模式/创建模型/单例模式.html">
            
                    
                        <b>1.15.2.3.</b>
                    
                    单例模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.2.4" data-path="../设计模式/创建模型/原型模式.html">
            
                <a href="../设计模式/创建模型/原型模式.html">
            
                    
                        <b>1.15.2.4.</b>
                    
                    原型模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.2.5" data-path="../设计模式/创建模型/工厂方法.html">
            
                <a href="../设计模式/创建模型/工厂方法.html">
            
                    
                        <b>1.15.2.5.</b>
                    
                    工厂方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.2.6" data-path="../设计模式/创建模型/抽象工厂.html">
            
                <a href="../设计模式/创建模型/抽象工厂.html">
            
                    
                        <b>1.15.2.6.</b>
                    
                    抽象工厂
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.2.7" data-path="../设计模式/创建模型/简单工厂.html">
            
                <a href="../设计模式/创建模型/简单工厂.html">
            
                    
                        <b>1.15.2.7.</b>
                    
                    简单工厂
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.15.3" data-path="../设计模式/结构型模型/">
            
                <a href="../设计模式/结构型模型/">
            
                    
                        <b>1.15.3.</b>
                    
                    结构型模型
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.15.3.1" data-path="../设计模式/结构型模型/readme.html">
            
                <a href="../设计模式/结构型模型/readme.html">
            
                    
                        <b>1.15.3.1.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.3.2" data-path="../设计模式/结构型模型/享元模式.html">
            
                <a href="../设计模式/结构型模型/享元模式.html">
            
                    
                        <b>1.15.3.2.</b>
                    
                    享元模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.3.3" data-path="../设计模式/结构型模型/代理模式.html">
            
                <a href="../设计模式/结构型模型/代理模式.html">
            
                    
                        <b>1.15.3.3.</b>
                    
                    代理模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.3.4" data-path="../设计模式/结构型模型/外观模式.html">
            
                <a href="../设计模式/结构型模型/外观模式.html">
            
                    
                        <b>1.15.3.4.</b>
                    
                    外观模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.3.5" data-path="../设计模式/结构型模型/桥模式.html">
            
                <a href="../设计模式/结构型模型/桥模式.html">
            
                    
                        <b>1.15.3.5.</b>
                    
                    桥模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.3.6" data-path="../设计模式/结构型模型/组合模式.html">
            
                <a href="../设计模式/结构型模型/组合模式.html">
            
                    
                        <b>1.15.3.6.</b>
                    
                    组合模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.3.7" data-path="../设计模式/结构型模型/装饰模式.html">
            
                <a href="../设计模式/结构型模型/装饰模式.html">
            
                    
                        <b>1.15.3.7.</b>
                    
                    装饰模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.3.8" data-path="../设计模式/结构型模型/适配器模式.html">
            
                <a href="../设计模式/结构型模型/适配器模式.html">
            
                    
                        <b>1.15.3.8.</b>
                    
                    适配器模式
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.15.4" data-path="../设计模式/行为型模型/">
            
                <a href="../设计模式/行为型模型/">
            
                    
                        <b>1.15.4.</b>
                    
                    行为型模型
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.15.4.1" data-path="../设计模式/行为型模型/readme.html">
            
                <a href="../设计模式/行为型模型/readme.html">
            
                    
                        <b>1.15.4.1.</b>
                    
                    Readme
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4.2" data-path="../设计模式/行为型模型/中介者模式.html">
            
                <a href="../设计模式/行为型模型/中介者模式.html">
            
                    
                        <b>1.15.4.2.</b>
                    
                    中介者模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4.3" data-path="../设计模式/行为型模型/命令模式.html">
            
                <a href="../设计模式/行为型模型/命令模式.html">
            
                    
                        <b>1.15.4.3.</b>
                    
                    命令模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4.4" data-path="../设计模式/行为型模型/备忘录模式.html">
            
                <a href="../设计模式/行为型模型/备忘录模式.html">
            
                    
                        <b>1.15.4.4.</b>
                    
                    备忘录模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4.5" data-path="../设计模式/行为型模型/模板方法模式.html">
            
                <a href="../设计模式/行为型模型/模板方法模式.html">
            
                    
                        <b>1.15.4.5.</b>
                    
                    模板方法模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4.6" data-path="../设计模式/行为型模型/状态模式.html">
            
                <a href="../设计模式/行为型模型/状态模式.html">
            
                    
                        <b>1.15.4.6.</b>
                    
                    状态模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4.7" data-path="../设计模式/行为型模型/策略模式.html">
            
                <a href="../设计模式/行为型模型/策略模式.html">
            
                    
                        <b>1.15.4.7.</b>
                    
                    策略模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4.8" data-path="../设计模式/行为型模型/职责链模式.html">
            
                <a href="../设计模式/行为型模型/职责链模式.html">
            
                    
                        <b>1.15.4.8.</b>
                    
                    职责链模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4.9" data-path="../设计模式/行为型模型/观察者模式.html">
            
                <a href="../设计模式/行为型模型/观察者模式.html">
            
                    
                        <b>1.15.4.9.</b>
                    
                    观察者模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4.10" data-path="../设计模式/行为型模型/解释器模式.html">
            
                <a href="../设计模式/行为型模型/解释器模式.html">
            
                    
                        <b>1.15.4.10.</b>
                    
                    解释器模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4.11" data-path="../设计模式/行为型模型/访问者模式.html">
            
                <a href="../设计模式/行为型模型/访问者模式.html">
            
                    
                        <b>1.15.4.11.</b>
                    
                    访问者模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4.12" data-path="../设计模式/行为型模型/迭代器模式.html">
            
                <a href="../设计模式/行为型模型/迭代器模式.html">
            
                    
                        <b>1.15.4.12.</b>
                    
                    迭代器模式
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >Deployment 的实现原理</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-anchor"></i><ul><li><a href="#&#x8BE6;&#x89E3;-kubernetes-deployment-&#x7684;&#x5B9E;&#x73B0;&#x539F;&#x7406;">&#x8BE6;&#x89E3; Kubernetes Deployment &#x7684;&#x5B9E;&#x73B0;&#x539F;&#x7406;</a></li><ul><li><a href="#&#x6982;&#x8FF0;">&#x6982;&#x8FF0;</a></li><li><a href="#&#x5B9E;&#x73B0;&#x539F;&#x7406;">&#x5B9E;&#x73B0;&#x539F;&#x7406;</a></li><ul><li><a href="#&#x540C;&#x6B65;">&#x540C;&#x6B65;</a></li><li><a href="#&#x56DE;&#x6EDA;">&#x56DE;&#x6EDA;</a></li><li><a href="#&#x6682;&#x505C;&#x548C;&#x6062;&#x590D;">&#x6682;&#x505C;&#x548C;&#x6062;&#x590D;</a></li><li><a href="#&#x5220;&#x9664;">&#x5220;&#x9664;</a></li></ul><li><a href="#&#x603B;&#x7ED3;">&#x603B;&#x7ED3;</a></li></ul></ul></div><a href="#&#x8BE6;&#x89E3;-kubernetes-deployment-&#x7684;&#x5B9E;&#x73B0;&#x539F;&#x7406;" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><h1 id="&#x8BE6;&#x89E3;-kubernetes-deployment-&#x7684;&#x5B9E;&#x73B0;&#x539F;&#x7406;"><a name="&#x8BE6;&#x89E3;-kubernetes-deployment-&#x7684;&#x5B9E;&#x73B0;&#x539F;&#x7406;" class="anchor-navigation-ex-anchor" href="#&#x8BE6;&#x89E3;-kubernetes-deployment-&#x7684;&#x5B9E;&#x73B0;&#x539F;&#x7406;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x8BE6;&#x89E3; Kubernetes Deployment &#x7684;&#x5B9E;&#x73B0;&#x539F;&#x7406;</h1>
<p>2019-02-24 <a href="https://draveness.me/tags/kubernetes" target="_blank">Kubernetes</a> <a href="https://draveness.me/tags/&#x5BB9;&#x5668;&#x7F16;&#x6392;" target="_blank">&#x5BB9;&#x5668;&#x7F16;&#x6392;</a> <a href="https://draveness.me/tags/deployment" target="_blank">Deployment</a> <a href="https://draveness.me/tags/&#x6EDA;&#x52A8;&#x66F4;&#x65B0;" target="_blank">&#x6EDA;&#x52A8;&#x66F4;&#x65B0;</a></p>
<p>&#x5982;&#x679C;&#x4F60;&#x5728;&#x751F;&#x4EA7;&#x73AF;&#x5883;&#x4E2D;&#x4F7F;&#x7528;&#x8FC7; Kubernetes&#xFF0C;&#x90A3;&#x4E48;&#x76F8;&#x4FE1;&#x4F60;&#x5BF9; Deployment &#x4E00;&#x5B9A;&#x4E0D;&#x4F1A;&#x964C;&#x751F;&#xFF0C;Deployment &#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x79CD;&#x5BF9; <a href="https://draveness.me/kubernetes-pod" target="_blank">Pod</a> &#x548C; <a href="https://draveness.me/kubernetes-replicaset" target="_blank">ReplicaSet</a> &#x7684;&#x7BA1;&#x7406;&#x65B9;&#x5F0F;&#xFF0C;&#x6BCF;&#x4E00;&#x4E2A; Deployment &#x90FD;&#x5BF9;&#x5E94;&#x96C6;&#x7FA4;&#x4E2D;&#x7684;&#x4E00;&#x6B21;&#x90E8;&#x7F72;&#xFF0C;&#x662F;&#x975E;&#x5E38;&#x5E38;&#x89C1;&#x7684; Kubernetes &#x5BF9;&#x8C61;&#x3002;</p>
<p>&#x6211;&#x4EEC;&#x5728;&#x8FD9;&#x7BC7;&#x6587;&#x7AE0;&#x4E2D;&#x5C31;&#x4F1A;&#x4ECB;&#x7ECD; Deployment &#x7684;&#x5B9E;&#x73B0;&#x539F;&#x7406;&#xFF0C;&#x5305;&#x62EC;&#x5B83;&#x662F;&#x5982;&#x4F55;&#x5904;&#x7406; Pod &#x7684;&#x6EDA;&#x52A8;&#x66F4;&#x65B0;&#x3001;&#x56DE;&#x6EDA;&#x4EE5;&#x53CA;&#x652F;&#x6301;&#x526F;&#x672C;&#x7684;&#x6C34;&#x5E73;&#x6269;&#x5BB9;&#x3002;</p>
<h2 id="&#x6982;&#x8FF0;"><a name="&#x6982;&#x8FF0;" class="anchor-navigation-ex-anchor" href="#&#x6982;&#x8FF0;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x6982;&#x8FF0;</h2>
<p>&#x4F5C;&#x4E3A;&#x6700;&#x5E38;&#x7528;&#x7684; Kubernetes &#x5BF9;&#x8C61;&#xFF0C;Deployment &#x7ECF;&#x5E38;&#x4F1A;&#x7528;&#x6765;&#x521B;&#x5EFA; <a href="https://draveness.me/kubernetes-replicaset" target="_blank">ReplicaSet</a> &#x548C; <a href="https://draveness.me/kubernetes-pod" target="_blank">Pod</a>&#xFF0C;&#x6211;&#x4EEC;&#x5F80;&#x5F80;&#x4E0D;&#x4F1A;&#x76F4;&#x63A5;&#x5728;&#x96C6;&#x7FA4;&#x4E2D;&#x4F7F;&#x7528; ReplicaSet &#x90E8;&#x7F72;&#x4E00;&#x4E2A;&#x65B0;&#x7684;&#x5FAE;&#x670D;&#x52A1;&#xFF0C;&#x4E00;&#x65B9;&#x9762;&#x662F;&#x56E0;&#x4E3A; ReplicaSet &#x7684;&#x529F;&#x80FD;&#x5176;&#x5B9E;&#x4E0D;&#x591F;&#x5F3A;&#x5927;&#xFF0C;&#x4E00;&#x4E9B;&#x5E38;&#x89C1;&#x7684;&#x66F4;&#x65B0;&#x3001;&#x6269;&#x5BB9;&#x548C;&#x7F29;&#x5BB9;&#x8FD0;&#x7EF4;&#x64CD;&#x4F5C;&#x90FD;&#x4E0D;&#x652F;&#x6301;&#xFF0C;Deployment &#x7684;&#x5F15;&#x5165;&#x5C31;&#x662F;&#x4E3A;&#x4E86;&#x5C31;&#x662F;&#x4E3A;&#x4E86;&#x652F;&#x6301;&#x8FD9;&#x4E9B;&#x590D;&#x6742;&#x7684;&#x64CD;&#x4F5C;&#x3002;</p>
<pre class="language-"><code class="lang-yaml"><span class="token key atrule">apiVersion</span><span class="token punctuation">:</span> apps/v1
<span class="token key atrule">kind</span><span class="token punctuation">:</span> Deployment
<span class="token key atrule">metadata</span><span class="token punctuation">:</span>
  <span class="token key atrule">name</span><span class="token punctuation">:</span> nginx<span class="token punctuation">-</span>deployment
  <span class="token key atrule">labels</span><span class="token punctuation">:</span>
    <span class="token key atrule">app</span><span class="token punctuation">:</span> nginx
<span class="token key atrule">spec</span><span class="token punctuation">:</span>
  <span class="token key atrule">replicas</span><span class="token punctuation">:</span> <span class="token number">3</span>
  <span class="token key atrule">selector</span><span class="token punctuation">:</span>
    <span class="token key atrule">matchLabels</span><span class="token punctuation">:</span>
      <span class="token key atrule">app</span><span class="token punctuation">:</span> nginx
  <span class="token key atrule">template</span><span class="token punctuation">:</span>
    <span class="token key atrule">metadata</span><span class="token punctuation">:</span>
      <span class="token key atrule">labels</span><span class="token punctuation">:</span>
        <span class="token key atrule">app</span><span class="token punctuation">:</span> nginx
    <span class="token key atrule">spec</span><span class="token punctuation">:</span>
      <span class="token key atrule">containers</span><span class="token punctuation">:</span>
      <span class="token punctuation">-</span> <span class="token key atrule">name</span><span class="token punctuation">:</span> nginx
        <span class="token key atrule">image</span><span class="token punctuation">:</span> nginx<span class="token punctuation">:</span>1.7.9
        <span class="token key atrule">ports</span><span class="token punctuation">:</span>
        <span class="token punctuation">-</span> <span class="token key atrule">containerPort</span><span class="token punctuation">:</span> <span class="token number">80</span>
</code></pre>
<p>YAML</p>
<p>&#x5F53;&#x6211;&#x4EEC;&#x5728; Kubernetes &#x96C6;&#x7FA4;&#x4E2D;&#x521B;&#x5EFA;&#x4E0A;&#x8FF0; Deployment &#x5BF9;&#x8C61;&#x65F6;&#xFF0C;&#x5B83;&#x4E0D;&#x53EA;&#x4F1A;&#x521B;&#x5EFA; Deployment &#x8D44;&#x6E90;&#xFF0C;&#x8FD8;&#x4F1A;&#x521B;&#x5EFA;&#x53E6;&#x5916;&#x7684; ReplicaSet &#x4EE5;&#x53CA;&#x4E09;&#x4E2A; Pod &#x5BF9;&#x8C61;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">$ kubectl get deployments.apps
NAME               READY     UP-TO-DATE   AVAILABLE   AGE
nginx-deployment   <span class="token number">3</span>/3       <span class="token number">3</span>            <span class="token number">3</span>           6m55s

$ kubectl get replicasets.apps
NAME                          DESIRED   CURRENT   READY     AGE
nginx-deployment-76bf4969df   <span class="token number">3</span>         <span class="token number">3</span>         <span class="token number">3</span>         7m27s

$ kubectl get pods
NAME                                READY     STATUS    RESTARTS   AGE
nginx-deployment-76bf4969df-58gxj   <span class="token number">1</span>/1       Running   <span class="token number">0</span>          7m42s
nginx-deployment-76bf4969df-9jgk9   <span class="token number">1</span>/1       Running   <span class="token number">0</span>          7m42s
nginx-deployment-76bf4969df-m4pkg   <span class="token number">1</span>/1       Running   <span class="token number">0</span>          7m43s
</code></pre>
<p>Bash</p>
<p>&#x6BCF;&#x4E00;&#x4E2A; Deployment &#x90FD;&#x4F1A;&#x548C;&#x5B83;&#x7684;&#x4F9D;&#x8D56;&#x7EC4;&#x6210;&#x4EE5;&#x4E0B;&#x7684;&#x62D3;&#x6251;&#x7ED3;&#x6784;&#xFF0C;&#x5728;&#x8FD9;&#x4E2A;&#x62D3;&#x6251;&#x7ED3;&#x6784;&#x4E2D;&#x7684;&#x5B50;&#x8282;&#x70B9;&#x90FD;&#x662F;&#x300E;&#x7A33;&#x5B9A;&#x300F;&#x7684;&#xFF0C;&#x4EFB;&#x610F;&#x8282;&#x70B9;&#x7684;&#x5220;&#x9664;&#x90FD;&#x4F1A;&#x88AB; Kubernetes &#x7684;&#x63A7;&#x5236;&#x5668;&#x91CD;&#x542F;&#xFF1A;</p>
<div class="mermaid">
graph TD
    Deployment-.-&gt;ReplicaSet
    ReplicaSet-.-&gt;Pod1
    ReplicaSet-.-&gt;Pod2
    ReplicaSet-.-&gt;Pod3
</div>

<p>Mermaid</p>
<p>&#x6240;&#x6709;&#x7684; Deployment &#x5BF9;&#x8C61;&#x90FD;&#x662F;&#x7531; Kubernetes &#x96C6;&#x7FA4;&#x4E2D;&#x7684; <code>DeploymentController</code> &#x8FDB;&#x884C;&#x7BA1;&#x7406;&#xFF0C;&#x5BB6;&#x4E0B;&#x6765;&#x6211;&#x4EEC;&#x5C06;&#x5F00;&#x59CB;&#x4ECB;&#x7ECD;&#x8BE5;&#x63A7;&#x5236;&#x5668;&#x7684;&#x5B9E;&#x73B0;&#x539F;&#x7406;&#x3002;</p>
<h2 id="&#x5B9E;&#x73B0;&#x539F;&#x7406;"><a name="&#x5B9E;&#x73B0;&#x539F;&#x7406;" class="anchor-navigation-ex-anchor" href="#&#x5B9E;&#x73B0;&#x539F;&#x7406;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5B9E;&#x73B0;&#x539F;&#x7406;</h2>
<p><code>DeploymentController</code> &#x4F5C;&#x4E3A;&#x7BA1;&#x7406; Deployment &#x8D44;&#x6E90;&#x7684;&#x63A7;&#x5236;&#x5668;&#xFF0C;&#x4F1A;&#x5728;&#x542F;&#x52A8;&#x65F6;&#x901A;&#x8FC7; <code>Informer</code> &#x76D1;&#x542C;&#x4E09;&#x79CD;&#x4E0D;&#x540C;&#x8D44;&#x6E90;&#x7684;&#x901A;&#x77E5;&#xFF0C;Pod&#x3001;ReplicaSet &#x548C; Deployment&#xFF0C;&#x8FD9;&#x4E09;&#x79CD;&#x8D44;&#x6E90;&#x7684;&#x53D8;&#x52A8;&#x90FD;&#x4F1A;&#x89E6;&#x53D1; <code>DeploymentController</code> &#x4E2D;&#x7684;&#x56DE;&#x8C03;&#x3002;</p>
<div class="mermaid">
graph TD
    DI[DeploymentInformer]-. Add/Update/Delete .-&gt;DC[DeploymentController]
    ReplicaSetInformer-. Add/Update/Delete .-&gt;DC
    PodInformer-. Delete .-&gt;DC
</div>

<p>Mermaid</p>
<p>&#x4E0D;&#x540C;&#x7684;&#x4E8B;&#x4EF6;&#x6700;&#x7EC8;&#x90FD;&#x4F1A;&#x5728;&#x88AB;&#x8FC7;&#x6EE4;&#x540E;&#x8FDB;&#x5165;&#x63A7;&#x5236;&#x5668;&#x6301;&#x6709;&#x7684;&#x961F;&#x5217;&#xFF0C;&#x7B49;&#x5F85;&#x5DE5;&#x4F5C;&#x8FDB;&#x7A0B;&#x7684;&#x6D88;&#x8D39;&#xFF0C;&#x4E0B;&#x9762;&#x7684;&#x8FD9;&#x4E9B;&#x4E8B;&#x4EF6;&#x90FD;&#x4F1A;&#x89E6;&#x53D1; Deployment &#x7684;&#x540C;&#x6B65;&#xFF1A;</p>
<ol>
<li>Deployment &#x7684;&#x53D8;&#x52A8;&#xFF1B;</li>
<li>Deployment &#x76F8;&#x5173;&#x7684; ReplicaSet &#x53D8;&#x52A8;&#xFF1B;</li>
<li>Deployment &#x76F8;&#x5173;&#x7684; Pod &#x6570;&#x91CF;&#x4E3A; 0 &#x65F6;&#xFF0C;Pod &#x7684;&#x5220;&#x9664;&#x4E8B;&#x4EF6;&#xFF1B;</li>
</ol>
<p><code>DeploymentController</code> &#x4F1A;&#x5728;&#x8C03;&#x7528; <code>Run</code> &#x65B9;&#x6CD5;&#x65F6;&#x542F;&#x52A8;&#x591A;&#x4E2A;&#x5DE5;&#x4F5C;&#x8FDB;&#x7A0B;&#xFF0C;&#x8FD9;&#x4E9B;&#x5DE5;&#x4F5C;&#x8FDB;&#x7A0B;&#x4F1A;&#x8FD0;&#x884C; <code>worker</code> &#x65B9;&#x6CD5;&#x4ECE;&#x961F;&#x5217;&#x4E2D;&#x8BFB;&#x53D6;&#x6700;&#x65B0;&#x7684; Deployment &#x5BF9;&#x8C61;&#x8FDB;&#x884C;&#x540C;&#x6B65;&#x3002;</p>
<h3 id="&#x540C;&#x6B65;"><a name="&#x540C;&#x6B65;" class="anchor-navigation-ex-anchor" href="#&#x540C;&#x6B65;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x540C;&#x6B65;</h3>
<p>Deployment &#x5BF9;&#x8C61;&#x7684;&#x540C;&#x6B65;&#x90FD;&#x662F;&#x901A;&#x8FC7;&#x4EE5;&#x4E0B;&#x7684; <code>syncDeployment</code> &#x65B9;&#x6CD5;&#x8FDB;&#x884C;&#x7684;&#xFF0C;&#x8BE5;&#x65B9;&#x6CD5;&#x5305;&#x542B;&#x4E86;&#x540C;&#x6B65;&#x3001;&#x56DE;&#x6EDA;&#x4EE5;&#x53CA;&#x66F4;&#x65B0;&#x7684;&#x903B;&#x8F91;&#xFF0C;&#x662F;&#x540C;&#x6B65; Deployment &#x8D44;&#x6E90;&#x7684;&#x552F;&#x4E00;&#x5165;&#x53E3;&#xFF1A;</p>
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>dc <span class="token operator">*</span>DeploymentController<span class="token punctuation">)</span> <span class="token function">syncDeployment</span><span class="token punctuation">(</span>key <span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token builtin">error</span> <span class="token punctuation">{</span>
    namespace<span class="token punctuation">,</span> name<span class="token punctuation">,</span> <span class="token boolean">_</span> <span class="token operator">:=</span> cache<span class="token punctuation">.</span><span class="token function">SplitMetaNamespaceKey</span><span class="token punctuation">(</span>key<span class="token punctuation">)</span>
    deployment<span class="token punctuation">,</span> <span class="token boolean">_</span> <span class="token operator">:=</span> dc<span class="token punctuation">.</span>dLister<span class="token punctuation">.</span><span class="token function">Deployments</span><span class="token punctuation">(</span>namespace<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">Get</span><span class="token punctuation">(</span>name<span class="token punctuation">)</span>

    d <span class="token operator">:=</span> deployment<span class="token punctuation">.</span><span class="token function">DeepCopy</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

    rsList<span class="token punctuation">,</span> <span class="token boolean">_</span> <span class="token operator">:=</span> dc<span class="token punctuation">.</span><span class="token function">getReplicaSetsForDeployment</span><span class="token punctuation">(</span>d<span class="token punctuation">)</span>
    podMap<span class="token punctuation">,</span> <span class="token boolean">_</span> <span class="token operator">:=</span> dc<span class="token punctuation">.</span><span class="token function">getPodMapForDeployment</span><span class="token punctuation">(</span>d<span class="token punctuation">,</span> rsList<span class="token punctuation">)</span>

    dc<span class="token punctuation">.</span><span class="token function">checkPausedConditions</span><span class="token punctuation">(</span>d<span class="token punctuation">)</span>

    <span class="token keyword">if</span> d<span class="token punctuation">.</span>Spec<span class="token punctuation">.</span>Paused <span class="token punctuation">{</span>
        <span class="token keyword">return</span> dc<span class="token punctuation">.</span><span class="token function">sync</span><span class="token punctuation">(</span>d<span class="token punctuation">,</span> rsList<span class="token punctuation">)</span>
    <span class="token punctuation">}</span>

    scalingEvent<span class="token punctuation">,</span> <span class="token boolean">_</span> <span class="token operator">:=</span> dc<span class="token punctuation">.</span><span class="token function">isScalingEvent</span><span class="token punctuation">(</span>d<span class="token punctuation">,</span> rsList<span class="token punctuation">)</span>
    <span class="token keyword">if</span> scalingEvent <span class="token punctuation">{</span>
        <span class="token keyword">return</span> dc<span class="token punctuation">.</span><span class="token function">sync</span><span class="token punctuation">(</span>d<span class="token punctuation">,</span> rsList<span class="token punctuation">)</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">switch</span> d<span class="token punctuation">.</span>Spec<span class="token punctuation">.</span>Strategy<span class="token punctuation">.</span>Type <span class="token punctuation">{</span>
    <span class="token keyword">case</span> apps<span class="token punctuation">.</span>RecreateDeploymentStrategyType<span class="token punctuation">:</span>
        <span class="token keyword">return</span> dc<span class="token punctuation">.</span><span class="token function">rolloutRecreate</span><span class="token punctuation">(</span>d<span class="token punctuation">,</span> rsList<span class="token punctuation">,</span> podMap<span class="token punctuation">)</span>
    <span class="token keyword">case</span> apps<span class="token punctuation">.</span>RollingUpdateDeploymentStrategyType<span class="token punctuation">:</span>
        <span class="token keyword">return</span> dc<span class="token punctuation">.</span><span class="token function">rolloutRolling</span><span class="token punctuation">(</span>d<span class="token punctuation">,</span> rsList<span class="token punctuation">)</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">return</span> fmt<span class="token punctuation">.</span><span class="token function">Errorf</span><span class="token punctuation">(</span><span class="token string">&quot;unexpected deployment strategy type: %s&quot;</span><span class="token punctuation">,</span> d<span class="token punctuation">.</span>Spec<span class="token punctuation">.</span>Strategy<span class="token punctuation">.</span>Type<span class="token punctuation">)</span>
<span class="token punctuation">}</span>
</code></pre>
<p>Go</p>
<ol>
<li><p>&#x6839;&#x636E;&#x4F20;&#x5165;&#x7684;&#x952E;&#x83B7;&#x53D6; Deployment &#x8D44;&#x6E90;&#xFF1B;</p>
</li>
<li><p>&#x8C03;&#x7528;</p>
</li>
</ol>
<pre class="language-"><code>   getReplicaSetsForDeployment
</code></pre><p>   &#x83B7;&#x53D6;&#x96C6;&#x7FA4;&#x4E2D;&#x4E0E; Deployment &#x76F8;&#x5173;&#x7684;&#x5168;&#x90E8; ReplicaSet&#xFF1B;</p>
<ol>
<li>&#x67E5;&#x627E;&#x96C6;&#x7FA4;&#x4E2D;&#x7684;&#x5168;&#x90E8; ReplicaSet&#xFF1B;</li>
<li>&#x6839;&#x636E; Deployment &#x7684;&#x9009;&#x62E9;&#x5668;&#x5BF9; ReplicaSet &#x5EFA;&#x7ACB;&#x6216;&#x8005;&#x91CA;&#x653E;&#x4ECE;&#x5C5E;&#x5173;&#x7CFB;&#xFF1B;</li>
</ol>
<ol>
<li>&#x8C03;&#x7528;</li>
</ol>
<pre class="language-"><code>   getPodMapForDeployment
</code></pre><p>   &#x83B7;&#x53D6;&#x5F53;&#x524D; Deployment &#x5BF9;&#x8C61;&#x76F8;&#x5173;&#x7684;&#x4ECE; ReplicaSet &#x5230; Pod &#x7684;&#x6620;&#x5C04;&#xFF1B;</p>
<ol>
<li>&#x6839;&#x636E;&#x9009;&#x62E9;&#x5668;&#x67E5;&#x627E;&#x5168;&#x90E8;&#x7684; Pod&#xFF1B;</li>
<li>&#x6839;&#x636E; Pod &#x7684;&#x63A7;&#x5236;&#x5668; ReplicaSet &#x5BF9;&#x4E0A;&#x8FF0; Pod &#x8FDB;&#x884C;&#x5206;&#x7C7B;&#xFF1B;</li>
</ol>
<ol>
<li><p>&#x5982;&#x679C;&#x5F53;&#x524D;&#x7684; Deployment &#x5904;&#x4E8E;&#x6682;&#x505C;&#x72B6;&#x6001;&#x6216;&#x8005;&#x9700;&#x8981;&#x8FDB;&#x884C;&#x6269;&#x5BB9;&#xFF0C;&#x5C31;&#x4F1A;&#x8C03;&#x7528; <code>sync</code> &#x65B9;&#x6CD5;&#x540C;&#x6B65; Deployment;</p>
</li>
<li><p>&#x5728;&#x6B63;&#x5E38;&#x60C5;&#x51B5;&#x4E0B;&#x4F1A;&#x6839;&#x636E;&#x89C4;&#x683C;&#x4E2D;&#x7684;&#x7B56;&#x7565;&#x5BF9; Deployment &#x8FDB;&#x884C;&#x66F4;&#x65B0;&#xFF1B;</p>
<ol>
<li><code>Recreate</code> &#x7B56;&#x7565;&#x4F1A;&#x8C03;&#x7528; <code>rolloutRecreate</code> &#x65B9;&#x6CD5;&#xFF0C;&#x5B83;&#x4F1A;&#x5148;&#x6740;&#x6389;&#x6240;&#x6709;&#x5B58;&#x5728;&#x7684; Pod &#x540E;&#x542F;&#x52A8;&#x65B0;&#x7684; Pod &#x526F;&#x672C;&#xFF1B;</li>
<li><code>RollingUpdate</code> &#x7B56;&#x7565;&#x4F1A;&#x8C03;&#x7528; <code>rolloutRolling</code> &#x65B9;&#x6CD5;&#xFF0C;&#x6839;&#x636E; <code>maxSurge</code> &#x548C; <code>maxUnavailable</code> &#x914D;&#x7F6E;&#x5BF9; Pod &#x8FDB;&#x884C;&#x6EDA;&#x52A8;&#x66F4;&#x65B0;&#xFF1B;</li>
</ol>
</li>
</ol>
<p>&#x8FD9;&#x5C31;&#x662F; Deployment &#x8D44;&#x6E90;&#x540C;&#x6B65;&#x7684;&#x4E3B;&#x8981;&#x6D41;&#x7A0B;&#xFF0C;&#x6211;&#x4EEC;&#x5728;&#x8FD9;&#x91CC;&#x53EF;&#x4EE5;&#x5173;&#x6CE8;&#x4E00;&#x4E0B; <code>getReplicaSetsForDeployment</code> &#x65B9;&#x6CD5;&#xFF1A;</p>
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>dc <span class="token operator">*</span>DeploymentController<span class="token punctuation">)</span> <span class="token function">getReplicaSetsForDeployment</span><span class="token punctuation">(</span>d <span class="token operator">*</span>apps<span class="token punctuation">.</span>Deployment<span class="token punctuation">)</span> <span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token operator">*</span>apps<span class="token punctuation">.</span>ReplicaSet<span class="token punctuation">,</span> <span class="token builtin">error</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    rsList<span class="token punctuation">,</span> <span class="token boolean">_</span> <span class="token operator">:=</span> dc<span class="token punctuation">.</span>rsLister<span class="token punctuation">.</span><span class="token function">ReplicaSets</span><span class="token punctuation">(</span>d<span class="token punctuation">.</span>Namespace<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">List</span><span class="token punctuation">(</span>labels<span class="token punctuation">.</span><span class="token function">Everything</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
    deploymentSelector<span class="token punctuation">,</span> <span class="token boolean">_</span> <span class="token operator">:=</span> metav1<span class="token punctuation">.</span><span class="token function">LabelSelectorAsSelector</span><span class="token punctuation">(</span>d<span class="token punctuation">.</span>Spec<span class="token punctuation">.</span>Selector<span class="token punctuation">)</span>
    canAdoptFunc <span class="token operator">:=</span> controller<span class="token punctuation">.</span><span class="token function">RecheckDeletionTimestamp</span><span class="token punctuation">(</span><span class="token keyword">func</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>metav1<span class="token punctuation">.</span>Object<span class="token punctuation">,</span> <span class="token builtin">error</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> dc<span class="token punctuation">.</span>client<span class="token punctuation">.</span><span class="token function">AppsV1</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">Deployments</span><span class="token punctuation">(</span>d<span class="token punctuation">.</span>Namespace<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">Get</span><span class="token punctuation">(</span>d<span class="token punctuation">.</span>Name<span class="token punctuation">,</span> metav1<span class="token punctuation">.</span>GetOptions<span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span>
    cm <span class="token operator">:=</span> controller<span class="token punctuation">.</span><span class="token function">NewReplicaSetControllerRefManager</span><span class="token punctuation">(</span>dc<span class="token punctuation">.</span>rsControl<span class="token punctuation">,</span> d<span class="token punctuation">,</span> deploymentSelector<span class="token punctuation">,</span> controllerKind<span class="token punctuation">,</span> canAdoptFunc<span class="token punctuation">)</span>
    <span class="token keyword">return</span> cm<span class="token punctuation">.</span><span class="token function">ClaimReplicaSets</span><span class="token punctuation">(</span>rsList<span class="token punctuation">)</span>
<span class="token punctuation">}</span>
</code></pre>
<p>Go</p>
<p>&#x8BE5;&#x65B9;&#x6CD5;&#x83B7;&#x53D6; Deployment &#x6301;&#x6709;&#x7684; ReplicaSet &#x65F6;&#x4F1A;&#x91CD;&#x65B0;&#x4E0E;&#x96C6;&#x7FA4;&#x4E2D;&#x7B26;&#x5408;&#x6761;&#x4EF6;&#x7684; ReplicaSet &#x901A;&#x8FC7; <code>ownerReferences</code> &#x5EFA;&#x7ACB;&#x5173;&#x7CFB;&#xFF0C;&#x6267;&#x884C;&#x7684;&#x903B;&#x8F91;&#x4E0E; <a href="https://draveness.me/kubernetes-replicaset" target="_blank">ReplicaSet</a> &#x8C03;&#x7528; <code>AdoptPod/ReleasePod</code> &#x51E0;&#x4E4E;&#x5B8C;&#x5168;&#x76F8;&#x540C;&#x3002;</p>
<h4 id="&#x6269;&#x5BB9;"><a name="&#x6269;&#x5BB9;" class="anchor-navigation-ex-anchor" href="#&#x6269;&#x5BB9;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x6269;&#x5BB9;</h4>
<p>&#x5982;&#x679C;&#x5F53;&#x524D;&#x9700;&#x8981;&#x66F4;&#x65B0;&#x7684; Deployment &#x7ECF;&#x8FC7; <code>isScalingEvent</code> &#x7684;&#x68C0;&#x67E5;&#x53D1;&#x73B0;&#x66F4;&#x65B0;&#x4E8B;&#x4EF6;&#x5B9E;&#x9645;&#x4E0A;&#x662F;&#x4E00;&#x6B21;&#x6269;&#x5BB9;&#x6216;&#x8005;&#x7F29;&#x5BB9;&#xFF0C;&#x4E5F;&#x5C31;&#x662F; ReplicaSet &#x6301;&#x6709;&#x7684; Pod &#x6570;&#x91CF;&#x548C;&#x89C4;&#x683C;&#x4E2D;&#x7684; <code>Replicas</code> &#x5B57;&#x6BB5;&#x5E76;&#x4E0D;&#x4E00;&#x81F4;&#xFF0C;&#x90A3;&#x4E48;&#x5C31;&#x4F1A;&#x8C03;&#x7528; <code>sync</code> &#x65B9;&#x6CD5;&#x5BF9; Deployment &#x8FDB;&#x884C;&#x540C;&#x6B65;&#xFF1A;</p>
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>dc <span class="token operator">*</span>DeploymentController<span class="token punctuation">)</span> <span class="token function">sync</span><span class="token punctuation">(</span>d <span class="token operator">*</span>apps<span class="token punctuation">.</span>Deployment<span class="token punctuation">,</span> rsList <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token operator">*</span>apps<span class="token punctuation">.</span>ReplicaSet<span class="token punctuation">)</span> <span class="token builtin">error</span> <span class="token punctuation">{</span>
    newRS<span class="token punctuation">,</span> oldRSs<span class="token punctuation">,</span> <span class="token boolean">_</span> <span class="token operator">:=</span> dc<span class="token punctuation">.</span><span class="token function">getAllReplicaSetsAndSyncRevision</span><span class="token punctuation">(</span>d<span class="token punctuation">,</span> rsList<span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span>
    dc<span class="token punctuation">.</span><span class="token function">scale</span><span class="token punctuation">(</span>d<span class="token punctuation">,</span> newRS<span class="token punctuation">,</span> oldRSs<span class="token punctuation">)</span>

    allRSs <span class="token operator">:=</span> <span class="token function">append</span><span class="token punctuation">(</span>oldRSs<span class="token punctuation">,</span> newRS<span class="token punctuation">)</span>
    <span class="token keyword">return</span> dc<span class="token punctuation">.</span><span class="token function">syncDeploymentStatus</span><span class="token punctuation">(</span>allRSs<span class="token punctuation">,</span> newRS<span class="token punctuation">,</span> d<span class="token punctuation">)</span>
<span class="token punctuation">}</span>
</code></pre>
<p>Go</p>
<p>&#x540C;&#x6B65;&#x7684;&#x8FC7;&#x7A0B;&#x5176;&#x5B9E;&#x6BD4;&#x8F83;&#x7B80;&#x5355;&#xFF0C;&#x8BE5;&#x65B9;&#x6CD5;&#x4F1A;&#x4ECE; apiserver &#x4E2D;&#x62FF;&#x5230;&#x5F53;&#x524D; Deployment &#x5BF9;&#x5E94;&#x7684;&#x6700;&#x65B0; ReplicaSet &#x548C;&#x5386;&#x53F2;&#x7684; ReplicaSet &#x5E76;&#x8C03;&#x7528; <code>scale</code> &#x65B9;&#x6CD5;&#x5F00;&#x59CB;&#x6269;&#x5BB9;&#xFF0C;<code>scale</code> &#x5C31;&#x662F;&#x6269;&#x5BB9;&#x9700;&#x8981;&#x6267;&#x884C;&#x7684;&#x4E3B;&#x8981;&#x65B9;&#x6CD5;&#xFF0C;&#x6211;&#x4EEC;&#x5C06;&#x4E0B;&#x9762;&#x7684;&#x65B9;&#x6CD5;&#x5206;&#x6210;&#x51E0;&#x90E8;&#x5206;&#x4F9D;&#x6B21;&#x8FDB;&#x884C;&#x4ECB;&#x7ECD;&#xFF1A;</p>
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>dc <span class="token operator">*</span>DeploymentController<span class="token punctuation">)</span> <span class="token function">scale</span><span class="token punctuation">(</span>deployment <span class="token operator">*</span>apps<span class="token punctuation">.</span>Deployment<span class="token punctuation">,</span> newRS <span class="token operator">*</span>apps<span class="token punctuation">.</span>ReplicaSet<span class="token punctuation">,</span> oldRSs <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token operator">*</span>apps<span class="token punctuation">.</span>ReplicaSet<span class="token punctuation">)</span> <span class="token builtin">error</span> <span class="token punctuation">{</span>
    <span class="token keyword">if</span> activeOrLatest <span class="token operator">:=</span> deploymentutil<span class="token punctuation">.</span><span class="token function">FindActiveOrLatest</span><span class="token punctuation">(</span>newRS<span class="token punctuation">,</span> oldRSs<span class="token punctuation">)</span><span class="token punctuation">;</span> activeOrLatest <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
        <span class="token keyword">if</span> <span class="token operator">*</span><span class="token punctuation">(</span>activeOrLatest<span class="token punctuation">.</span>Spec<span class="token punctuation">.</span>Replicas<span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token operator">*</span><span class="token punctuation">(</span>deployment<span class="token punctuation">.</span>Spec<span class="token punctuation">.</span>Replicas<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">return</span> <span class="token boolean">nil</span>
        <span class="token punctuation">}</span>
        dc<span class="token punctuation">.</span><span class="token function">scaleReplicaSetAndRecordEvent</span><span class="token punctuation">(</span>activeOrLatest<span class="token punctuation">,</span> <span class="token operator">*</span><span class="token punctuation">(</span>deployment<span class="token punctuation">.</span>Spec<span class="token punctuation">.</span>Replicas<span class="token punctuation">)</span><span class="token punctuation">,</span> deployment<span class="token punctuation">)</span>
        <span class="token keyword">return</span> <span class="token boolean">nil</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">if</span> deploymentutil<span class="token punctuation">.</span><span class="token function">IsSaturated</span><span class="token punctuation">(</span>deployment<span class="token punctuation">,</span> newRS<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">for</span> <span class="token boolean">_</span><span class="token punctuation">,</span> old <span class="token operator">:=</span> <span class="token keyword">range</span> controller<span class="token punctuation">.</span><span class="token function">FilterActiveReplicaSets</span><span class="token punctuation">(</span>oldRSs<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            dc<span class="token punctuation">.</span><span class="token function">scaleReplicaSetAndRecordEvent</span><span class="token punctuation">(</span>old<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> deployment<span class="token punctuation">)</span>
        <span class="token punctuation">}</span>
        <span class="token keyword">return</span> <span class="token boolean">nil</span>
    <span class="token punctuation">}</span>
</code></pre>
<p>Go</p>
<p>&#x5982;&#x679C;&#x96C6;&#x7FA4;&#x4E2D;&#x53EA;&#x6709;&#x4E00;&#x4E2A;&#x6D3B;&#x8DC3;&#x7684; ReplicaSet&#xFF0C;&#x90A3;&#x4E48;&#x5C31;&#x4F1A;&#x5BF9;&#x8BE5; ReplicaSet &#x8FDB;&#x884C;&#x6269;&#x7F29;&#x5BB9;&#xFF0C;&#x4F46;&#x662F;&#x5982;&#x679C;&#x4E0D;&#x5B58;&#x5728;&#x6D3B;&#x8DC3;&#x7684; ReplicaSet &#x5BF9;&#x8C61;&#xFF0C;&#x5C31;&#x4F1A;&#x9009;&#x62E9;&#x6700;&#x65B0;&#x7684; ReplicaSet &#x8FDB;&#x884C;&#x64CD;&#x4F5C;&#xFF0C;&#x8FD9;&#x90E8;&#x5206;&#x9009;&#x62E9; ReplicaSet &#x7684;&#x5DE5;&#x4F5C;&#x90FD;&#x662F;&#x7531; <code>FindActiveOrLatest</code> &#x548C; <code>scaleReplicaSetAndRecordEvent</code> &#x5171;&#x540C;&#x5B8C;&#x6210;&#x7684;&#x3002;</p>
<p>&#x5F53;&#x8C03;&#x7528; <code>IsSaturated</code> &#x65B9;&#x6CD5;&#x53D1;&#x73B0;&#x5F53;&#x524D;&#x7684; Deployment &#x5BF9;&#x5E94;&#x7684;&#x526F;&#x672C;&#x6570;&#x91CF;&#x5DF2;&#x7ECF;&#x9971;&#x548C;&#x65F6;&#x5C31;&#x4F1A;&#x5220;&#x9664;&#x6240;&#x6709;&#x5386;&#x53F2;&#x7248;&#x672C; ReplicaSet &#x6301;&#x6709;&#x7684; Pod &#x526F;&#x672C;&#x3002;</p>
<p><img src="https://img.draveness.me/2019-02-24-kubernetes-deployment-scale-replicas.png" alt="kubernetes-deployment-scale-replicas"></p>
<p>&#x4F46;&#x662F;&#x5728; Deployment &#x4F7F;&#x7528;&#x6EDA;&#x52A8;&#x66F4;&#x65B0;&#x7B56;&#x7565;&#x65F6;&#xFF0C;&#x5982;&#x679C;&#x53D1;&#x73B0;&#x5F53;&#x524D;&#x7684; ReplicaSet &#x5E76;&#x6CA1;&#x6709;&#x9971;&#x548C;&#x5E76;&#x4E14;&#x5B58;&#x5728;&#x591A;&#x4E2A;&#x6D3B;&#x8DC3;&#x7684; ReplicaSet &#x5BF9;&#x8C61;&#x5C31;&#x4F1A;&#x6309;&#x7167;&#x6BD4;&#x4F8B;&#x5206;&#x522B;&#x5BF9;&#x5404;&#x4E2A;&#x6D3B;&#x8DC3;&#x7684; ReplicaSet &#x8FDB;&#x884C;&#x6269;&#x5BB9;&#x6216;&#x8005;&#x7F29;&#x5BB9;&#xFF1A;</p>
<pre class="language-"><code class="lang-go">    <span class="token keyword">if</span> deploymentutil<span class="token punctuation">.</span><span class="token function">IsRollingUpdate</span><span class="token punctuation">(</span>deployment<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        allRSs <span class="token operator">:=</span> controller<span class="token punctuation">.</span><span class="token function">FilterActiveReplicaSets</span><span class="token punctuation">(</span><span class="token function">append</span><span class="token punctuation">(</span>oldRSs<span class="token punctuation">,</span> newRS<span class="token punctuation">)</span><span class="token punctuation">)</span>
        allRSsReplicas <span class="token operator">:=</span> deploymentutil<span class="token punctuation">.</span><span class="token function">GetReplicaCountForReplicaSets</span><span class="token punctuation">(</span>allRSs<span class="token punctuation">)</span>

        allowedSize <span class="token operator">:=</span> <span class="token function">int32</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span>
        <span class="token keyword">if</span> <span class="token operator">*</span><span class="token punctuation">(</span>deployment<span class="token punctuation">.</span>Spec<span class="token punctuation">.</span>Replicas<span class="token punctuation">)</span> <span class="token operator">&gt;</span> <span class="token number">0</span> <span class="token punctuation">{</span>
            allowedSize <span class="token operator">=</span> <span class="token operator">*</span><span class="token punctuation">(</span>deployment<span class="token punctuation">.</span>Spec<span class="token punctuation">.</span>Replicas<span class="token punctuation">)</span> <span class="token operator">+</span> deploymentutil<span class="token punctuation">.</span><span class="token function">MaxSurge</span><span class="token punctuation">(</span><span class="token operator">*</span>deployment<span class="token punctuation">)</span>
        <span class="token punctuation">}</span>

        deploymentReplicasToAdd <span class="token operator">:=</span> allowedSize <span class="token operator">-</span> allRSsReplicas

        <span class="token keyword">var</span> scalingOperation <span class="token builtin">string</span>
        <span class="token keyword">switch</span> <span class="token punctuation">{</span>
        <span class="token keyword">case</span> deploymentReplicasToAdd <span class="token operator">&gt;</span> <span class="token number">0</span><span class="token punctuation">:</span>
            sort<span class="token punctuation">.</span><span class="token function">Sort</span><span class="token punctuation">(</span>controller<span class="token punctuation">.</span><span class="token function">ReplicaSetsBySizeNewer</span><span class="token punctuation">(</span>allRSs<span class="token punctuation">)</span><span class="token punctuation">)</span>
            scalingOperation <span class="token operator">=</span> <span class="token string">&quot;up&quot;</span>

        <span class="token keyword">case</span> deploymentReplicasToAdd <span class="token operator">&lt;</span> <span class="token number">0</span><span class="token punctuation">:</span>
            sort<span class="token punctuation">.</span><span class="token function">Sort</span><span class="token punctuation">(</span>controller<span class="token punctuation">.</span><span class="token function">ReplicaSetsBySizeOlder</span><span class="token punctuation">(</span>allRSs<span class="token punctuation">)</span><span class="token punctuation">)</span>
            scalingOperation <span class="token operator">=</span> <span class="token string">&quot;down&quot;</span>
        <span class="token punctuation">}</span>
</code></pre>
<p>Go</p>
<ol>
<li><p>&#x901A;&#x8FC7; <code>FilterActiveReplicaSets</code> &#x83B7;&#x53D6;&#x6240;&#x6709;&#x6D3B;&#x8DC3;&#x7684; ReplicaSet &#x5BF9;&#x8C61;&#xFF1B;</p>
</li>
<li><p>&#x8C03;&#x7528; <code>GetReplicaCountForReplicaSets</code> &#x8BA1;&#x7B97;&#x5F53;&#x524D; Deployment &#x5BF9;&#x5E94; ReplicaSet &#x6301;&#x6709;&#x7684;&#x5168;&#x90E8; Pod &#x526F;&#x672C;&#x4E2A;&#x6570;&#xFF1B;</p>
</li>
<li><p>&#x6839;&#x636E; Deployment &#x5BF9;&#x8C61;&#x914D;&#x7F6E;&#x7684; <code>Replicas</code> &#x548C;&#x6700;&#x5927;&#x989D;&#x5916;&#x53EF;&#x4EE5;&#x5B58;&#x5728;&#x7684;&#x526F;&#x672C;&#x6570; <code>maxSurge</code> &#x4EE5;&#x8BA1;&#x7B97; Deployment &#x5141;&#x8BB8;&#x521B;&#x5EFA;&#x7684; Pod &#x6570;&#x91CF;&#xFF1B;</p>
</li>
<li><p>&#x901A;&#x8FC7; <code>allowedSize</code> &#x548C; <code>allRSsReplicas</code> &#x8BA1;&#x7B97;&#x51FA;&#x9700;&#x8981;&#x589E;&#x52A0;&#x6216;&#x8005;&#x5220;&#x9664;&#x7684;&#x526F;&#x672C;&#x6570;&#xFF1B;</p>
</li>
<li><p>&#x6839;&#x636E;</p>
</li>
</ol>
<pre class="language-"><code>   deploymentReplicasToAdd
</code></pre><p>   &#x53D8;&#x91CF;&#x7684;&#x7B26;&#x53F7;&#x5BF9; ReplicaSet &#x6570;&#x7EC4;&#x8FDB;&#x884C;&#x6392;&#x5E8F;&#x5E76;&#x786E;&#x5B9A;&#x5F53;&#x524D;&#x7684;&#x64CD;&#x4F5C;&#x65F6;&#x6269;&#x5BB9;&#x8FD8;&#x662F;&#x7F29;&#x5BB9;&#xFF1B;</p>
<ol>
<li>&#x5982;&#x679C; <code>deploymentReplicasToAdd &gt; 0</code>&#xFF0C;ReplicaSet &#x5C06;&#x6309;&#x7167;&#x4ECE;&#x65B0;&#x5230;&#x65E7;&#x7684;&#x987A;&#x5E8F;&#x4F9D;&#x6B21;&#x8FDB;&#x884C;&#x6269;&#x5BB9;&#xFF1B;</li>
<li>&#x5982;&#x679C; <code>deploymentReplicasToAdd &lt; 0</code>&#xFF0C;ReplicaSet &#x5C06;&#x6309;&#x7167;&#x4ECE;&#x65E7;&#x5230;&#x65B0;&#x7684;&#x987A;&#x5E8F;&#x4F9D;&#x6B21;&#x8FDB;&#x884C;&#x7F29;&#x5BB9;&#xFF1B;</li>
</ol>
<blockquote>
<p><code>maxSurge</code>&#x3001;<code>maxUnavailable</code> &#x662F;&#x4E24;&#x4E2A;&#x5904;&#x7406;&#x6EDA;&#x52A8;&#x66F4;&#x65B0;&#x65F6;&#x9700;&#x8981;&#x5173;&#x6CE8;&#x7684;&#x53C2;&#x6570;&#xFF0C;&#x6211;&#x4EEC;&#x4F1A;&#x5728;&#x6EDA;&#x52A8;&#x66F4;&#x65B0;&#x4E00;&#x8282;&#x4E2D;&#x5177;&#x4F53;&#x4ECB;&#x7ECD;&#x3002;</p>
</blockquote>
<pre class="language-"><code class="lang-go">        deploymentReplicasAdded <span class="token operator">:=</span> <span class="token function">int32</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span>
        nameToSize <span class="token operator">:=</span> <span class="token function">make</span><span class="token punctuation">(</span><span class="token keyword">map</span><span class="token punctuation">[</span><span class="token builtin">string</span><span class="token punctuation">]</span><span class="token builtin">int32</span><span class="token punctuation">)</span>
        <span class="token keyword">for</span> i <span class="token operator">:=</span> <span class="token keyword">range</span> allRSs <span class="token punctuation">{</span>
            rs <span class="token operator">:=</span> allRSs<span class="token punctuation">[</span>i<span class="token punctuation">]</span>

            <span class="token keyword">if</span> deploymentReplicasToAdd <span class="token operator">!=</span> <span class="token number">0</span> <span class="token punctuation">{</span>
                proportion <span class="token operator">:=</span> deploymentutil<span class="token punctuation">.</span><span class="token function">GetProportion</span><span class="token punctuation">(</span>rs<span class="token punctuation">,</span> <span class="token operator">*</span>deployment<span class="token punctuation">,</span> deploymentReplicasToAdd<span class="token punctuation">,</span> deploymentReplicasAdded<span class="token punctuation">)</span>

                nameToSize<span class="token punctuation">[</span>rs<span class="token punctuation">.</span>Name<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token operator">*</span><span class="token punctuation">(</span>rs<span class="token punctuation">.</span>Spec<span class="token punctuation">.</span>Replicas<span class="token punctuation">)</span> <span class="token operator">+</span> proportion
                deploymentReplicasAdded <span class="token operator">+=</span> proportion
            <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
                nameToSize<span class="token punctuation">[</span>rs<span class="token punctuation">.</span>Name<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token operator">*</span><span class="token punctuation">(</span>rs<span class="token punctuation">.</span>Spec<span class="token punctuation">.</span>Replicas<span class="token punctuation">)</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
</code></pre>
<p>Go</p>
<p>&#x56E0;&#x4E3A;&#x5F53;&#x524D;&#x7684; Deployment &#x6301;&#x6709;&#x4E86;&#x591A;&#x4E2A;&#x6D3B;&#x8DC3;&#x7684; ReplicaSet&#xFF0C;&#x6240;&#x4EE5;&#x5728;&#x8BA1;&#x7B97;&#x4E86;&#x9700;&#x8981;&#x589E;&#x52A0;&#x6216;&#x8005;&#x5220;&#x9664;&#x7684;&#x526F;&#x672C;&#x4E2A;&#x6570; <code>deploymentReplicasToAdd</code> &#x4E4B;&#x540E;&#xFF0C;&#x5C31;&#x4F1A;&#x4E3A;&#x591A;&#x4E2A;&#x6D3B;&#x8DC3;&#x7684; ReplicaSet &#x5206;&#x914D;&#x6BCF;&#x4E2A; ReplicaSet &#x9700;&#x8981;&#x6539;&#x53D8;&#x7684;&#x526F;&#x672C;&#x6570;&#xFF0C;<code>GetProportion</code> &#x4F1A;&#x6839;&#x636E;&#x4EE5;&#x4E0B;&#x51E0;&#x4E2A;&#x53C2;&#x6570;&#x51B3;&#x5B9A;&#x6700;&#x540E;&#x7684;&#x7ED3;&#x679C;:</p>
<ol>
<li>Deployment &#x671F;&#x671B;&#x7684; Pod &#x526F;&#x672C;&#x6570;&#x91CF;&#xFF1B;</li>
<li>&#x9700;&#x8981;&#x65B0;&#x589E;&#x6216;&#x8005;&#x51CF;&#x5C11;&#x7684;&#x526F;&#x672C;&#x6570;&#x91CF;&#xFF1B;</li>
<li>Deployment &#x5F53;&#x524D;&#x901A;&#x8FC7; ReplicaSet &#x6301;&#x6709; Pod &#x7684;&#x603B;&#x6570;&#x91CF;&#xFF1B;</li>
</ol>
<p>Kubernetes &#x4F1A;&#x5728; <code>getReplicaSetFraction</code> &#x4F7F;&#x7528;&#x4E0B;&#x9762;&#x7684;&#x516C;&#x5F0F;&#x8BA1;&#x7B97;&#x6BCF;&#x4E00;&#x4E2A; ReplicaSet &#x5728; Deployment &#x8D44;&#x6E90;&#x4E2D;&#x7684;&#x5360;&#x6BD4;&#xFF0C;&#x6700;&#x540E;&#x4F1A;&#x8FD4;&#x56DE;&#x8BE5; ReplicaSet &#x9700;&#x8981;&#x6539;&#x53D8;&#x7684;&#x526F;&#x672C;&#x6570;&#xFF1A;</p>
<p><img src="https://img.draveness.me/2019-02-24-deployment-replicaset-get-proportion.png" alt="deployment-replicaset-get-proportion"></p>
<p>&#x8BE5;&#x7ED3;&#x679C;&#x53C8;&#x4F1A;&#x4E0E;&#x76EE;&#x524D;&#x671F;&#x671B;&#x7684;&#x5269;&#x4F59;&#x53D8;&#x5316;&#x91CF;&#x8FDB;&#x884C;&#x5BF9;&#x6BD4;&#xFF0C;&#x4FDD;&#x8BC1;&#x53D8;&#x5316;&#x7684;&#x526F;&#x672C;&#x6570;&#x91CF;&#x4E0D;&#x4F1A;&#x8D85;&#x8FC7;&#x671F;&#x671B;&#x503C;&#x3002;</p>
<pre class="language-"><code class="lang-go">        <span class="token keyword">for</span> i <span class="token operator">:=</span> <span class="token keyword">range</span> allRSs <span class="token punctuation">{</span>
            rs <span class="token operator">:=</span> allRSs<span class="token punctuation">[</span>i<span class="token punctuation">]</span>

            <span class="token comment">// ...</span>

            dc<span class="token punctuation">.</span><span class="token function">scaleReplicaSet</span><span class="token punctuation">(</span>rs<span class="token punctuation">,</span> nameToSize<span class="token punctuation">[</span>rs<span class="token punctuation">.</span>Name<span class="token punctuation">]</span><span class="token punctuation">,</span> deployment<span class="token punctuation">,</span> scalingOperation<span class="token punctuation">)</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">return</span> <span class="token boolean">nil</span>
<span class="token punctuation">}</span>
</code></pre>
<p>Go</p>
<p>&#x5728; <code>scale</code> &#x65B9;&#x6CD5;&#x7684;&#x6700;&#x540E;&#x4F1A;&#x76F4;&#x63A5;&#x8C03;&#x7528; <code>scaleReplicaSet</code> &#x5C06;&#x6BCF;&#x4E00;&#x4E2A; ReplicaSet &#x90FD;&#x6269;&#x5BB9;&#x6216;&#x8005;&#x7F29;&#x5BB9;&#x5230;&#x6211;&#x4EEC;&#x671F;&#x671B;&#x7684;&#x526F;&#x672C;&#x6570;&#xFF1A;</p>
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>dc <span class="token operator">*</span>DeploymentController<span class="token punctuation">)</span> <span class="token function">scaleReplicaSet</span><span class="token punctuation">(</span>rs <span class="token operator">*</span>apps<span class="token punctuation">.</span>ReplicaSet<span class="token punctuation">,</span> newScale <span class="token builtin">int32</span><span class="token punctuation">,</span> deployment <span class="token operator">*</span>apps<span class="token punctuation">.</span>Deployment<span class="token punctuation">,</span> scalingOperation <span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token punctuation">(</span><span class="token builtin">bool</span><span class="token punctuation">,</span> <span class="token operator">*</span>apps<span class="token punctuation">.</span>ReplicaSet<span class="token punctuation">,</span> <span class="token builtin">error</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    sizeNeedsUpdate <span class="token operator">:=</span> <span class="token operator">*</span><span class="token punctuation">(</span>rs<span class="token punctuation">.</span>Spec<span class="token punctuation">.</span>Replicas<span class="token punctuation">)</span> <span class="token operator">!=</span> newScale

    annotationsNeedUpdate <span class="token operator">:=</span> deploymentutil<span class="token punctuation">.</span><span class="token function">ReplicasAnnotationsNeedUpdate</span><span class="token punctuation">(</span>rs<span class="token punctuation">,</span> <span class="token operator">*</span><span class="token punctuation">(</span>deployment<span class="token punctuation">.</span>Spec<span class="token punctuation">.</span>Replicas<span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token operator">*</span><span class="token punctuation">(</span>deployment<span class="token punctuation">.</span>Spec<span class="token punctuation">.</span>Replicas<span class="token punctuation">)</span><span class="token operator">+</span>deploymentutil<span class="token punctuation">.</span><span class="token function">MaxSurge</span><span class="token punctuation">(</span><span class="token operator">*</span>deployment<span class="token punctuation">)</span><span class="token punctuation">)</span>

    <span class="token keyword">if</span> sizeNeedsUpdate <span class="token operator">||</span> annotationsNeedUpdate <span class="token punctuation">{</span>
        rsCopy <span class="token operator">:=</span> rs<span class="token punctuation">.</span><span class="token function">DeepCopy</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token operator">*</span><span class="token punctuation">(</span>rsCopy<span class="token punctuation">.</span>Spec<span class="token punctuation">.</span>Replicas<span class="token punctuation">)</span> <span class="token operator">=</span> newScale
        deploymentutil<span class="token punctuation">.</span><span class="token function">SetReplicasAnnotations</span><span class="token punctuation">(</span>rsCopy<span class="token punctuation">,</span> <span class="token operator">*</span><span class="token punctuation">(</span>deployment<span class="token punctuation">.</span>Spec<span class="token punctuation">.</span>Replicas<span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token operator">*</span><span class="token punctuation">(</span>deployment<span class="token punctuation">.</span>Spec<span class="token punctuation">.</span>Replicas<span class="token punctuation">)</span><span class="token operator">+</span>deploymentutil<span class="token punctuation">.</span><span class="token function">MaxSurge</span><span class="token punctuation">(</span><span class="token operator">*</span>deployment<span class="token punctuation">)</span><span class="token punctuation">)</span>
        rs<span class="token punctuation">,</span> <span class="token boolean">_</span> <span class="token operator">=</span> dc<span class="token punctuation">.</span>client<span class="token punctuation">.</span><span class="token function">AppsV1</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">ReplicaSets</span><span class="token punctuation">(</span>rsCopy<span class="token punctuation">.</span>Namespace<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">Update</span><span class="token punctuation">(</span>rsCopy<span class="token punctuation">)</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">return</span> <span class="token boolean">true</span><span class="token punctuation">,</span> rs<span class="token punctuation">,</span> err
<span class="token punctuation">}</span>
</code></pre>
<p>Go</p>
<p>&#x8FD9;&#x91CC;&#x4F1A;&#x76F4;&#x63A5;&#x4FEE;&#x6539;&#x76EE;&#x6807; ReplicaSet &#x89C4;&#x683C;&#x4E2D;&#x7684; <code>Replicas</code> &#x53C2;&#x6570;&#x548C;&#x6CE8;&#x89E3; <code>deployment.kubernetes.io/desired-replicas</code> &#x7684;&#x503C;&#x5E76;&#x901A;&#x8FC7; API &#x8BF7;&#x6C42;&#x66F4;&#x65B0;&#x5F53;&#x524D;&#x7684; ReplicaSet &#x5BF9;&#x8C61;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">$ kubectl describe rs nginx-deployment-76bf4969df
Name:           nginx-deployment-76bf4969df
Namespace:      default
Selector:       <span class="token assign-left variable">app</span><span class="token operator">=</span>nginx,pod-template-hash<span class="token operator">=</span>76bf4969df
Labels:         <span class="token assign-left variable">app</span><span class="token operator">=</span>nginx
                pod-template-hash<span class="token operator">=</span>76bf4969df
Annotations:    deployment.kubernetes.io/desired-replicas<span class="token operator">=</span><span class="token number">3</span>
                deployment.kubernetes.io/max-replicas<span class="token operator">=</span><span class="token number">4</span>
<span class="token punctuation">..</span>.
</code></pre>
<p>Bash</p>
<p>&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x901A;&#x8FC7; <code>describe</code> &#x547D;&#x4EE4;&#x67E5;&#x770B; ReplicaSet &#x7684;&#x6CE8;&#x89E3;&#xFF0C;&#x5176;&#x5B9E;&#x80FD;&#x591F;&#x53D1;&#x73B0;&#x5F53;&#x524D; ReplicaSet &#x7684;&#x671F;&#x5F85;&#x526F;&#x672C;&#x6570;&#x548C;&#x6700;&#x5927;&#x526F;&#x672C;&#x6570;&#xFF0C;<code>deployment.kubernetes.io/desired-replicas</code> &#x6CE8;&#x89E3;&#x5C31;&#x662F;&#x5728;&#x4E0A;&#x8FF0;&#x65B9;&#x6CD5;&#x4E2D;&#x88AB; Kubernetes &#x7684; <code>DeploymentController</code> &#x66F4;&#x65B0;&#x7684;&#x3002;</p>
<h4 id="&#x91CD;&#x65B0;&#x521B;&#x5EFA;"><a name="&#x91CD;&#x65B0;&#x521B;&#x5EFA;" class="anchor-navigation-ex-anchor" href="#&#x91CD;&#x65B0;&#x521B;&#x5EFA;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x91CD;&#x65B0;&#x521B;&#x5EFA;</h4>
<p>&#x5F53; Deployment &#x4F7F;&#x7528;&#x7684;&#x66F4;&#x65B0;&#x7B56;&#x7565;&#x7C7B;&#x578B;&#x662F; <code>Recreate</code> &#x65F6;&#xFF0C;<code>DeploymentController</code> &#x5C31;&#x4F1A;&#x4F7F;&#x7528;&#x5982;&#x4E0B;&#x7684; <code>rolloutRecreate</code> &#x65B9;&#x6CD5;&#x5BF9; Deployment &#x8FDB;&#x884C;&#x66F4;&#x65B0;&#xFF1A;</p>
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>dc <span class="token operator">*</span>DeploymentController<span class="token punctuation">)</span> <span class="token function">rolloutRecreate</span><span class="token punctuation">(</span>d <span class="token operator">*</span>apps<span class="token punctuation">.</span>Deployment<span class="token punctuation">,</span> rsList <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token operator">*</span>apps<span class="token punctuation">.</span>ReplicaSet<span class="token punctuation">,</span> podMap <span class="token keyword">map</span><span class="token punctuation">[</span>types<span class="token punctuation">.</span>UID<span class="token punctuation">]</span><span class="token operator">*</span>v1<span class="token punctuation">.</span>PodList<span class="token punctuation">)</span> <span class="token builtin">error</span> <span class="token punctuation">{</span>
    newRS<span class="token punctuation">,</span> oldRSs<span class="token punctuation">,</span> <span class="token boolean">_</span> <span class="token operator">:=</span> dc<span class="token punctuation">.</span><span class="token function">getAllReplicaSetsAndSyncRevision</span><span class="token punctuation">(</span>d<span class="token punctuation">,</span> rsList<span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span>
    allRSs <span class="token operator">:=</span> <span class="token function">append</span><span class="token punctuation">(</span>oldRSs<span class="token punctuation">,</span> newRS<span class="token punctuation">)</span>
    activeOldRSs <span class="token operator">:=</span> controller<span class="token punctuation">.</span><span class="token function">FilterActiveReplicaSets</span><span class="token punctuation">(</span>oldRSs<span class="token punctuation">)</span>

    scaledDown<span class="token punctuation">,</span> <span class="token boolean">_</span> <span class="token operator">:=</span> dc<span class="token punctuation">.</span><span class="token function">scaleDownOldReplicaSetsForRecreate</span><span class="token punctuation">(</span>activeOldRSs<span class="token punctuation">,</span> d<span class="token punctuation">)</span>
    <span class="token keyword">if</span> scaledDown <span class="token punctuation">{</span>
        <span class="token keyword">return</span> dc<span class="token punctuation">.</span><span class="token function">syncRolloutStatus</span><span class="token punctuation">(</span>allRSs<span class="token punctuation">,</span> newRS<span class="token punctuation">,</span> d<span class="token punctuation">)</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">if</span> <span class="token function">oldPodsRunning</span><span class="token punctuation">(</span>newRS<span class="token punctuation">,</span> oldRSs<span class="token punctuation">,</span> podMap<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> dc<span class="token punctuation">.</span><span class="token function">syncRolloutStatus</span><span class="token punctuation">(</span>allRSs<span class="token punctuation">,</span> newRS<span class="token punctuation">,</span> d<span class="token punctuation">)</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">if</span> newRS <span class="token operator">==</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
        newRS<span class="token punctuation">,</span> oldRSs<span class="token punctuation">,</span> <span class="token boolean">_</span> <span class="token operator">=</span> dc<span class="token punctuation">.</span><span class="token function">getAllReplicaSetsAndSyncRevision</span><span class="token punctuation">(</span>d<span class="token punctuation">,</span> rsList<span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">)</span>
        allRSs <span class="token operator">=</span> <span class="token function">append</span><span class="token punctuation">(</span>oldRSs<span class="token punctuation">,</span> newRS<span class="token punctuation">)</span>
    <span class="token punctuation">}</span>

    dc<span class="token punctuation">.</span><span class="token function">scaleUpNewReplicaSetForRecreate</span><span class="token punctuation">(</span>newRS<span class="token punctuation">,</span> d<span class="token punctuation">)</span>

    <span class="token keyword">if</span> util<span class="token punctuation">.</span><span class="token function">DeploymentComplete</span><span class="token punctuation">(</span>d<span class="token punctuation">,</span> <span class="token operator">&amp;</span>d<span class="token punctuation">.</span>Status<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        dc<span class="token punctuation">.</span><span class="token function">cleanupDeployment</span><span class="token punctuation">(</span>oldRSs<span class="token punctuation">,</span> d<span class="token punctuation">)</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">return</span> dc<span class="token punctuation">.</span><span class="token function">syncRolloutStatus</span><span class="token punctuation">(</span>allRSs<span class="token punctuation">,</span> newRS<span class="token punctuation">,</span> d<span class="token punctuation">)</span>
<span class="token punctuation">}</span>
</code></pre>
<p>Go</p>
<ol>
<li>&#x5229;&#x7528; <code>getAllReplicaSetsAndSyncRevision</code> &#x548C; <code>FilterActiveReplicaSets</code> &#x4E24;&#x4E2A;&#x65B9;&#x6CD5;&#x83B7;&#x53D6; Deployment &#x4E2D;&#x6240;&#x6709;&#x7684; ReplicaSet &#x4EE5;&#x53CA;&#x5176;&#x4E2D;&#x6D3B;&#x8DC3;&#x7684; ReplicaSet &#x5BF9;&#x8C61;&#xFF1B;</li>
<li>&#x8C03;&#x7528; <code>scaleDownOldReplicaSetsForRecreate</code> &#x65B9;&#x6CD5;&#x5C06;&#x6240;&#x6709;&#x6D3B;&#x8DC3;&#x7684;&#x5386;&#x53F2; ReplicaSet &#x6301;&#x6709;&#x7684;&#x526F;&#x672C; Pod &#x6570;&#x76EE;&#x964D;&#x81F3; 0&#xFF1B;</li>
<li>&#x540C;&#x6B65; Deployment &#x7684;&#x6700;&#x65B0;&#x72B6;&#x6001;&#x5E76;&#x7B49;&#x5F85; Pod &#x7684;&#x7EC8;&#x6B62;&#xFF1B;</li>
<li>&#x5728;&#x9700;&#x8981;&#x65F6;&#x901A;&#x8FC7; <code>getAllReplicaSetsAndSyncRevision</code> &#x65B9;&#x6CD5;&#x521B;&#x5EFA;&#x65B0;&#x7684; ReplicaSet &#x5E76;&#x8C03;&#x7528; <code>scaleUpNewReplicaSetForRecreate</code> &#x51FD;&#x6570;&#x5BF9; ReplicaSet &#x8FDB;&#x884C;&#x6269;&#x5BB9;&#xFF1B;</li>
<li>&#x66F4;&#x65B0;&#x5B8C;&#x6210;&#x4E4B;&#x540E;&#x4F1A;&#x8C03;&#x7528; <code>cleanupDeployment</code> &#x65B9;&#x6CD5;&#x5220;&#x9664;&#x5386;&#x53F2;&#x5168;&#x90E8;&#x7684; ReplicaSet &#x5BF9;&#x8C61;&#x5E76;&#x66F4;&#x65B0; Deployment &#x7684;&#x72B6;&#x6001;&#xFF1B;</li>
</ol>
<p><img src="https://img.draveness.me/2019-02-24-kubernetes-deployment-rollout-recreate.png" alt="kubernetes-deployment-rollout-recreate"></p>
<p>&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#x5728;&#x66F4;&#x65B0;&#x7684;&#x8FC7;&#x7A0B;&#x4E2D;&#xFF0C;&#x4E4B;&#x524D;&#x521B;&#x5EFA;&#x7684; ReplicaSet &#x548C; Pod &#x8D44;&#x6E90;&#x5168;&#x90E8;&#x90FD;&#x4F1A;&#x88AB;&#x5220;&#x9664;&#xFF0C;&#x53EA;&#x662F; Pod &#x4F1A;&#x5148;&#x88AB;&#x5220;&#x9664;&#x800C; ReplicaSet &#x4F1A;&#x540E;&#x88AB;&#x5220;&#x9664;&#xFF1B;&#x4E0A;&#x8FF0;&#x65B9;&#x6CD5;&#x4E5F;&#x4F1A;&#x521B;&#x5EFA;&#x65B0;&#x7684; ReplicaSet &#x548C; Pod &#x5BF9;&#x8C61;&#xFF0C;&#x9700;&#x8981;&#x6CE8;&#x610F;&#x7684;&#x662F;&#x5728;&#x8FD9;&#x4E2A;&#x8FC7;&#x7A0B;&#x4E2D;&#x65E7;&#x7684; Pod &#x526F;&#x672C;&#x4E00;&#x5B9A;&#x4F1A;&#x5148;&#x88AB;&#x5220;&#x9664;&#xFF0C;&#x6240;&#x4EE5;&#x4F1A;&#x6709;&#x4E00;&#x6BB5;&#x65F6;&#x95F4;&#x4E0D;&#x5B58;&#x5728;&#x53EF;&#x7528;&#x7684; Pod&#x3002;</p>
<h4 id="&#x6EDA;&#x52A8;&#x66F4;&#x65B0;"><a name="&#x6EDA;&#x52A8;&#x66F4;&#x65B0;" class="anchor-navigation-ex-anchor" href="#&#x6EDA;&#x52A8;&#x66F4;&#x65B0;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x6EDA;&#x52A8;&#x66F4;&#x65B0;</h4>
<p>Deployment &#x7684;&#x53E6;&#x4E00;&#x4E2A;&#x66F4;&#x65B0;&#x7B56;&#x7565; <code>RollingUpdate</code> &#x5176;&#x5B9E;&#x66F4;&#x52A0;&#x5E38;&#x89C1;&#xFF0C;&#x5728;&#x5177;&#x4F53;&#x4ECB;&#x7ECD;&#x6EDA;&#x52A8;&#x66F4;&#x65B0;&#x7684;&#x6D41;&#x7A0B;&#x4E4B;&#x524D;&#xFF0C;&#x6211;&#x4EEC;&#x9996;&#x5148;&#x9700;&#x8981;&#x4E86;&#x89E3;&#x6EDA;&#x52A8;&#x66F4;&#x65B0;&#x7B56;&#x7565;&#x4F7F;&#x7528;&#x7684;&#x4E24;&#x4E2A;&#x53C2;&#x6570; <code>maxUnavailable</code> &#x548C; <code>maxSurge</code>&#xFF1A;</p>
<ul>
<li><code>maxUnavailable</code> &#x8868;&#x793A;&#x5728;&#x66F4;&#x65B0;&#x8FC7;&#x7A0B;&#x4E2D;&#x80FD;&#x591F;&#x8FDB;&#x5165;&#x4E0D;&#x53EF;&#x7528;&#x72B6;&#x6001;&#x7684; Pod &#x7684;&#x6700;&#x5927;&#x503C;&#xFF1B;</li>
<li><code>maxSurge</code> &#x8868;&#x793A;&#x80FD;&#x591F;&#x989D;&#x5916;&#x521B;&#x5EFA;&#x7684; Pod &#x4E2A;&#x6570;&#xFF1B;</li>
</ul>
<p><code>maxUnavailable</code> &#x548C; <code>maxSurge</code> &#x8FD9;&#x4E24;&#x4E2A;&#x6EDA;&#x52A8;&#x66F4;&#x65B0;&#x7684;&#x914D;&#x7F6E;&#x90FD;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x7EDD;&#x5BF9;&#x503C;&#x6216;&#x8005;&#x767E;&#x5206;&#x6BD4;&#x8868;&#x793A;&#xFF0C;&#x4F7F;&#x7528;&#x767E;&#x5206;&#x6BD4;&#x65F6;&#x9700;&#x8981;&#x7528; <code>Replicas * Strategy.RollingUpdate.MaxSurge</code> &#x516C;&#x5F0F;&#x8BA1;&#x7B97;&#x76F8;&#x5E94;&#x7684;&#x6570;&#x503C;&#x3002;</p>
<p><img src="https://img.draveness.me/2019-02-24-kubernetes-deployment-rolling-update-spec.png" alt="kubernetes-deployment-rolling-update-spe"></p>
<p><code>rolloutRolling</code> &#x65B9;&#x6CD5;&#x5C31;&#x662F; <code>DeploymentController</code> &#x7528;&#x4E8E;&#x5904;&#x7406;&#x6EDA;&#x52A8;&#x66F4;&#x65B0;&#x7684;&#x65B9;&#x6CD5;&#xFF1A;</p>
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>dc <span class="token operator">*</span>DeploymentController<span class="token punctuation">)</span> <span class="token function">rolloutRolling</span><span class="token punctuation">(</span>d <span class="token operator">*</span>apps<span class="token punctuation">.</span>Deployment<span class="token punctuation">,</span> rsList <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token operator">*</span>apps<span class="token punctuation">.</span>ReplicaSet<span class="token punctuation">)</span> <span class="token builtin">error</span> <span class="token punctuation">{</span>
    newRS<span class="token punctuation">,</span> oldRSs<span class="token punctuation">,</span> <span class="token boolean">_</span> <span class="token operator">:=</span> dc<span class="token punctuation">.</span><span class="token function">getAllReplicaSetsAndSyncRevision</span><span class="token punctuation">(</span>d<span class="token punctuation">,</span> rsList<span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">)</span>
    allRSs <span class="token operator">:=</span> <span class="token function">append</span><span class="token punctuation">(</span>oldRSs<span class="token punctuation">,</span> newRS<span class="token punctuation">)</span>

    scaledUp<span class="token punctuation">,</span> <span class="token boolean">_</span> <span class="token operator">:=</span> dc<span class="token punctuation">.</span><span class="token function">reconcileNewReplicaSet</span><span class="token punctuation">(</span>allRSs<span class="token punctuation">,</span> newRS<span class="token punctuation">,</span> d<span class="token punctuation">)</span>
    <span class="token keyword">if</span> scaledUp <span class="token punctuation">{</span>
        <span class="token keyword">return</span> dc<span class="token punctuation">.</span><span class="token function">syncRolloutStatus</span><span class="token punctuation">(</span>allRSs<span class="token punctuation">,</span> newRS<span class="token punctuation">,</span> d<span class="token punctuation">)</span>
    <span class="token punctuation">}</span>

    scaledDown<span class="token punctuation">,</span> <span class="token boolean">_</span> <span class="token operator">:=</span> dc<span class="token punctuation">.</span><span class="token function">reconcileOldReplicaSets</span><span class="token punctuation">(</span>allRSs<span class="token punctuation">,</span> controller<span class="token punctuation">.</span><span class="token function">FilterActiveReplicaSets</span><span class="token punctuation">(</span>oldRSs<span class="token punctuation">)</span><span class="token punctuation">,</span> newRS<span class="token punctuation">,</span> d<span class="token punctuation">)</span>
    <span class="token keyword">if</span> scaledDown <span class="token punctuation">{</span>
        <span class="token keyword">return</span> dc<span class="token punctuation">.</span><span class="token function">syncRolloutStatus</span><span class="token punctuation">(</span>allRSs<span class="token punctuation">,</span> newRS<span class="token punctuation">,</span> d<span class="token punctuation">)</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">if</span> deploymentutil<span class="token punctuation">.</span><span class="token function">DeploymentComplete</span><span class="token punctuation">(</span>d<span class="token punctuation">,</span> <span class="token operator">&amp;</span>d<span class="token punctuation">.</span>Status<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        dc<span class="token punctuation">.</span><span class="token function">cleanupDeployment</span><span class="token punctuation">(</span>oldRSs<span class="token punctuation">,</span> d<span class="token punctuation">)</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">return</span> dc<span class="token punctuation">.</span><span class="token function">syncRolloutStatus</span><span class="token punctuation">(</span>allRSs<span class="token punctuation">,</span> newRS<span class="token punctuation">,</span> d<span class="token punctuation">)</span>
<span class="token punctuation">}</span>
</code></pre>
<p>Go</p>
<ol>
<li>&#x9996;&#x5148;&#x83B7;&#x53D6; Deployment &#x5BF9;&#x5E94;&#x7684;&#x5168;&#x90E8; ReplicaSet &#x8D44;&#x6E90;&#xFF1B;</li>
<li>&#x901A;&#x8FC7; <code>reconcileNewReplicaSet</code> &#x8C03;&#x89E3;&#x65B0; ReplicaSet &#x7684;&#x526F;&#x672C;&#x6570;&#xFF0C;&#x521B;&#x5EFA;&#x65B0;&#x7684; Pod &#x5E76;&#x4FDD;&#x8BC1;&#x989D;&#x5916;&#x7684;&#x526F;&#x672C;&#x6570;&#x91CF;&#x4E0D;&#x8D85;&#x8FC7; <code>maxSurge</code>&#xFF1B;</li>
<li>&#x901A;&#x8FC7; <code>reconcileOldReplicaSets</code> &#x8C03;&#x89E3;&#x5386;&#x53F2; ReplicaSet &#x7684;&#x526F;&#x672C;&#x6570;&#xFF0C;&#x5220;&#x9664;&#x65E7;&#x7684; Pod &#x5E76;&#x4FDD;&#x8BC1;&#x4E0D;&#x53EF;&#x7528;&#x7684;&#x90E8;&#x5206;&#x6570;&#x4E0D;&#x4F1A;&#x8D85;&#x8FC7; <code>maxUnavailable</code>&#xFF1B;</li>
<li>&#x6700;&#x540E;&#x5220;&#x9664;&#x65E0;&#x7528;&#x7684; ReplicaSet &#x5E76;&#x66F4;&#x65B0; Deployment &#x7684;&#x72B6;&#x6001;&#xFF1B;</li>
</ol>
<p>&#x9700;&#x8981;&#x6CE8;&#x610F;&#x7684;&#x662F;&#xFF0C;&#x5728;&#x6EDA;&#x52A8;&#x66F4;&#x65B0;&#x7684;&#x8FC7;&#x7A0B;&#x4E2D;&#xFF0C;Kubernetes &#x5E76;&#x4E0D;&#x662F;&#x4E00;&#x6B21;&#x6027;&#x5C31;&#x5207;&#x6362;&#x5230;&#x671F;&#x671B;&#x7684;&#x72B6;&#x6001;&#xFF0C;&#x5373;&#x300E;&#x65B0; ReplicaSet &#x8FD0;&#x884C;&#x6307;&#x5B9A;&#x6570;&#x91CF;&#x7684;&#x526F;&#x672C;&#x300F;&#xFF0C;&#x800C;&#x662F;&#x4F1A;&#x5148;&#x542F;&#x52A8;&#x65B0;&#x7684; ReplicaSet &#x4EE5;&#x53CA;&#x4E00;&#x5B9A;&#x6570;&#x91CF;&#x7684; Pod &#x526F;&#x672C;&#xFF0C;&#x7136;&#x540E;&#x5220;&#x9664;&#x5386;&#x53F2; ReplicaSet &#x4E2D;&#x7684;&#x526F;&#x672C;&#xFF0C;&#x518D;&#x542F;&#x52A8;&#x4E00;&#x4E9B;&#x65B0; ReplicaSet &#x7684;&#x526F;&#x672C;&#xFF0C;&#x4E0D;&#x65AD;&#x5BF9;&#x65B0; ReplicaSet &#x8FDB;&#x884C;&#x6269;&#x5BB9;&#x5E76;&#x5BF9;&#x65E7; ReplicaSet &#x8FDB;&#x884C;&#x7F29;&#x5BB9;&#x6700;&#x7EC8;&#x8FBE;&#x5230;&#x4E86;&#x96C6;&#x7FA4;&#x671F;&#x671B;&#x7684;&#x72B6;&#x6001;&#x3002;</p>
<p>&#x5F53;&#x6211;&#x4EEC;&#x4F7F;&#x7528;&#x5982;&#x4E0B;&#x7684; <code>reconcileNewReplicaSet</code> &#x65B9;&#x6CD5;&#x5BF9;&#x65B0; ReplicaSet &#x8FDB;&#x884C;&#x8C03;&#x8282;&#x65F6;&#xFF0C;&#x6211;&#x4EEC;&#x4F1A;&#x53D1;&#x73B0;&#x5728;&#x65B0; ReplicaSet &#x4E2D;&#x526F;&#x672C;&#x6570;&#x91CF;&#x6EE1;&#x8DB3;&#x671F;&#x671B;&#x65F6;&#x4F1A;&#x76F4;&#x63A5;&#x8FD4;&#x56DE;&#xFF0C;&#x5728;&#x8D85;&#x8FC7;&#x671F;&#x671B;&#x65F6;&#x4F1A;&#x8FDB;&#x884C;&#x7F29;&#x5BB9;&#xFF1A;</p>
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>dc <span class="token operator">*</span>DeploymentController<span class="token punctuation">)</span> <span class="token function">reconcileNewReplicaSet</span><span class="token punctuation">(</span>allRSs <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token operator">*</span>apps<span class="token punctuation">.</span>ReplicaSet<span class="token punctuation">,</span> newRS <span class="token operator">*</span>apps<span class="token punctuation">.</span>ReplicaSet<span class="token punctuation">,</span> deployment <span class="token operator">*</span>apps<span class="token punctuation">.</span>Deployment<span class="token punctuation">)</span> <span class="token punctuation">(</span><span class="token builtin">bool</span><span class="token punctuation">,</span> <span class="token builtin">error</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">if</span> <span class="token operator">*</span><span class="token punctuation">(</span>newRS<span class="token punctuation">.</span>Spec<span class="token punctuation">.</span>Replicas<span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token operator">*</span><span class="token punctuation">(</span>deployment<span class="token punctuation">.</span>Spec<span class="token punctuation">.</span>Replicas<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token boolean">nil</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">if</span> <span class="token operator">*</span><span class="token punctuation">(</span>newRS<span class="token punctuation">.</span>Spec<span class="token punctuation">.</span>Replicas<span class="token punctuation">)</span> <span class="token operator">&gt;</span> <span class="token operator">*</span><span class="token punctuation">(</span>deployment<span class="token punctuation">.</span>Spec<span class="token punctuation">.</span>Replicas<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        scaled<span class="token punctuation">,</span> <span class="token boolean">_</span><span class="token punctuation">,</span> err <span class="token operator">:=</span> dc<span class="token punctuation">.</span><span class="token function">scaleReplicaSetAndRecordEvent</span><span class="token punctuation">(</span>newRS<span class="token punctuation">,</span> <span class="token operator">*</span><span class="token punctuation">(</span>deployment<span class="token punctuation">.</span>Spec<span class="token punctuation">.</span>Replicas<span class="token punctuation">)</span><span class="token punctuation">,</span> deployment<span class="token punctuation">)</span>
        <span class="token keyword">return</span> scaled<span class="token punctuation">,</span> err
    <span class="token punctuation">}</span>
    newReplicasCount<span class="token punctuation">,</span> <span class="token boolean">_</span> <span class="token operator">:=</span> deploymentutil<span class="token punctuation">.</span><span class="token function">NewRSNewReplicas</span><span class="token punctuation">(</span>deployment<span class="token punctuation">,</span> allRSs<span class="token punctuation">,</span> newRS<span class="token punctuation">)</span>
    scaled<span class="token punctuation">,</span> <span class="token boolean">_</span><span class="token punctuation">,</span> err <span class="token operator">:=</span> dc<span class="token punctuation">.</span><span class="token function">scaleReplicaSetAndRecordEvent</span><span class="token punctuation">(</span>newRS<span class="token punctuation">,</span> newReplicasCount<span class="token punctuation">,</span> deployment<span class="token punctuation">)</span>
    <span class="token keyword">return</span> scaled<span class="token punctuation">,</span> err
<span class="token punctuation">}</span>
</code></pre>
<p>Go</p>
<p>&#x5982;&#x679C; ReplicaSet &#x7684;&#x6570;&#x91CF;&#x4E0D;&#x591F;&#x5C31;&#x4F1A;&#x8C03;&#x7528; <code>NewRSNewReplicas</code> &#x51FD;&#x6570;&#x8BA1;&#x7B97;&#x65B0;&#x7684;&#x526F;&#x672C;&#x4E2A;&#x6570;&#xFF0C;&#x8BA1;&#x7B97;&#x7684;&#x8FC7;&#x7A0B;&#x4F7F;&#x7528;&#x4E86;&#x5982;&#x4E0B;&#x6240;&#x793A;&#x7684;&#x516C;&#x5F0F;&#xFF1A;</p>
<pre class="language-"><code class="lang-go">maxTotalPods <span class="token operator">=</span> deployment<span class="token punctuation">.</span>Spec<span class="token punctuation">.</span>Replicas <span class="token operator">+</span> 
currentPodCount <span class="token operator">=</span> <span class="token function">sum</span><span class="token punctuation">(</span>deployement<span class="token punctuation">.</span>ReplicaSets<span class="token punctuation">.</span>Replicas<span class="token punctuation">)</span>
scaleUpCount <span class="token operator">=</span> maxTotalPods <span class="token operator">-</span> currentPodCount
scaleUpCount <span class="token operator">=</span> <span class="token function">min</span><span class="token punctuation">(</span>scaleUpCount<span class="token punctuation">,</span> deployment<span class="token punctuation">.</span>Spec<span class="token punctuation">.</span>Replicas <span class="token operator">-</span> newRS<span class="token punctuation">.</span>Spec<span class="token punctuation">.</span>Replicas<span class="token punctuation">)</span><span class="token punctuation">)</span>
newRSNewReplicas <span class="token operator">=</span> newRS<span class="token punctuation">.</span>Spec<span class="token punctuation">.</span>Replicas <span class="token operator">+</span> scaleUpCount
</code></pre>
<p>Go</p>
<p>&#x8BE5;&#x8FC7;&#x7A0B;&#x603B;&#x5171;&#x9700;&#x8981;&#x8003;&#x8651; Deployment &#x671F;&#x671B;&#x7684;&#x526F;&#x672C;&#x6570;&#x91CF;&#x3001;&#x5F53;&#x524D;&#x53EF;&#x7528;&#x7684;&#x526F;&#x672C;&#x6570;&#x91CF;&#x4EE5;&#x53CA;&#x65B0; ReplicaSet &#x6301;&#x6709;&#x7684;&#x526F;&#x672C;&#xFF0C;&#x8FD8;&#x6709;&#x4E00;&#x4E9B;&#x6700;&#x5927;&#x503C;&#x548C;&#x6700;&#x5C0F;&#x503C;&#x7684;&#x9650;&#x5236;&#xFF0C;&#x4F8B;&#x5982;&#x989D;&#x5916; Pod &#x6570;&#x91CF;&#x4E0D;&#x80FD;&#x8D85;&#x8FC7; <code>maxSurge</code>&#x3001;&#x65B0; ReplicaSet &#x7684; Pod &#x6570;&#x91CF;&#x4E0D;&#x80FD;&#x8D85;&#x8FC7; Deployment &#x7684;&#x671F;&#x671B;&#x6570;&#x91CF;&#xFF0C;&#x9075;&#x5FAA;&#x8FD9;&#x4E9B;&#x89C4;&#x5219;&#x6211;&#x4EEC;&#x5C31;&#x80FD;&#x8BA1;&#x7B97;&#x51FA; <code>newRSNewReplicas</code>&#x3002;</p>
<p>&#x53E6;&#x4E00;&#x4E2A;&#x6EDA;&#x52A8;&#x66F4;&#x65B0;&#x4E2D;&#x4F7F;&#x7528;&#x7684;&#x65B9;&#x6CD5; <code>reconcileOldReplicaSets</code> &#x4E3B;&#x8981;&#x4F5C;&#x7528;&#x5C31;&#x662F;&#x5BF9;&#x5386;&#x53F2; ReplicaSet &#x5BF9;&#x8C61;&#x6301;&#x6709;&#x7684;&#x526F;&#x672C;&#x6570;&#x91CF;&#x8FDB;&#x884C;&#x7F29;&#x5BB9;&#xFF1A;</p>
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>dc <span class="token operator">*</span>DeploymentController<span class="token punctuation">)</span> <span class="token function">reconcileOldReplicaSets</span><span class="token punctuation">(</span>allRSs <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token operator">*</span>apps<span class="token punctuation">.</span>ReplicaSet<span class="token punctuation">,</span> oldRSs <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token operator">*</span>apps<span class="token punctuation">.</span>ReplicaSet<span class="token punctuation">,</span> newRS <span class="token operator">*</span>apps<span class="token punctuation">.</span>ReplicaSet<span class="token punctuation">,</span> deployment <span class="token operator">*</span>apps<span class="token punctuation">.</span>Deployment<span class="token punctuation">)</span> <span class="token punctuation">(</span><span class="token builtin">bool</span><span class="token punctuation">,</span> <span class="token builtin">error</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    oldPodsCount <span class="token operator">:=</span> deploymentutil<span class="token punctuation">.</span><span class="token function">GetReplicaCountForReplicaSets</span><span class="token punctuation">(</span>oldRSs<span class="token punctuation">)</span>
    <span class="token keyword">if</span> oldPodsCount <span class="token operator">==</span> <span class="token number">0</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token boolean">nil</span>
    <span class="token punctuation">}</span>

    allPodsCount <span class="token operator">:=</span> deploymentutil<span class="token punctuation">.</span><span class="token function">GetReplicaCountForReplicaSets</span><span class="token punctuation">(</span>allRSs<span class="token punctuation">)</span>
    maxUnavailable <span class="token operator">:=</span> deploymentutil<span class="token punctuation">.</span><span class="token function">MaxUnavailable</span><span class="token punctuation">(</span><span class="token operator">*</span>deployment<span class="token punctuation">)</span>

    minAvailable <span class="token operator">:=</span> <span class="token operator">*</span><span class="token punctuation">(</span>deployment<span class="token punctuation">.</span>Spec<span class="token punctuation">.</span>Replicas<span class="token punctuation">)</span> <span class="token operator">-</span> maxUnavailable
    newRSUnavailablePodCount <span class="token operator">:=</span> <span class="token operator">*</span><span class="token punctuation">(</span>newRS<span class="token punctuation">.</span>Spec<span class="token punctuation">.</span>Replicas<span class="token punctuation">)</span> <span class="token operator">-</span> newRS<span class="token punctuation">.</span>Status<span class="token punctuation">.</span>AvailableReplicas
    maxScaledDown <span class="token operator">:=</span> allPodsCount <span class="token operator">-</span> minAvailable <span class="token operator">-</span> newRSUnavailablePodCount
    <span class="token keyword">if</span> maxScaledDown <span class="token operator">&lt;=</span> <span class="token number">0</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token boolean">nil</span>
    <span class="token punctuation">}</span>

    oldRSs<span class="token punctuation">,</span> cleanupCount<span class="token punctuation">,</span> <span class="token boolean">_</span> <span class="token operator">:=</span> dc<span class="token punctuation">.</span><span class="token function">cleanupUnhealthyReplicas</span><span class="token punctuation">(</span>oldRSs<span class="token punctuation">,</span> deployment<span class="token punctuation">,</span> maxScaledDown<span class="token punctuation">)</span>

    allRSs <span class="token operator">=</span> <span class="token function">append</span><span class="token punctuation">(</span>oldRSs<span class="token punctuation">,</span> newRS<span class="token punctuation">)</span>
    scaledDownCount<span class="token punctuation">,</span> <span class="token boolean">_</span> <span class="token operator">:=</span> dc<span class="token punctuation">.</span><span class="token function">scaleDownOldReplicaSetsForRollingUpdate</span><span class="token punctuation">(</span>allRSs<span class="token punctuation">,</span> oldRSs<span class="token punctuation">,</span> deployment<span class="token punctuation">)</span>

    totalScaledDown <span class="token operator">:=</span> cleanupCount <span class="token operator">+</span> scaledDownCount
    <span class="token keyword">return</span> totalScaledDown <span class="token operator">&gt;</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token boolean">nil</span>
<span class="token punctuation">}</span>
</code></pre>
<p>Go</p>
<ol>
<li>&#x8BA1;&#x7B97;&#x5386;&#x53F2; ReplicaSet &#x6301;&#x6709;&#x7684;&#x526F;&#x672C;&#x603B;&#x6570;&#x91CF;&#xFF1B;</li>
<li>&#x8BA1;&#x7B97;&#x5168;&#x90E8; ReplicaSet &#x6301;&#x6709;&#x7684;&#x526F;&#x672C;&#x603B;&#x6570;&#x91CF;&#xFF1B;</li>
<li>&#x6839;&#x636E; Deployment &#x671F;&#x671B;&#x7684;&#x526F;&#x672C;&#x6570;&#x3001;&#x6700;&#x5927;&#x4E0D;&#x53EF;&#x7528;&#x526F;&#x672C;&#x6570;&#x4EE5;&#x53CA;&#x65B0; ReplicaSet &#x4E2D;&#x4E0D;&#x53EF;&#x7528;&#x7684; Pod &#x6570;&#x91CF;&#x8BA1;&#x7B97;&#x6700;&#x5927;&#x7F29;&#x5BB9;&#x7684;&#x526F;&#x672C;&#x4E2A;&#x6570;&#xFF1B;</li>
<li>&#x901A;&#x8FC7; <code>cleanupUnhealthyReplicas</code> &#x65B9;&#x6CD5;&#x6E05;&#x7406; ReplicaSet &#x4E2D;&#x5904;&#x4E8E;&#x4E0D;&#x5065;&#x5EB7;&#x72B6;&#x6001;&#x7684;&#x526F;&#x672C;&#xFF1B;</li>
<li>&#x8C03;&#x7528; <code>scaleDownOldReplicaSetsForRollingUpdate</code> &#x65B9;&#x6CD5;&#x5BF9;&#x5386;&#x53F2; ReplicaSet &#x4E2D;&#x7684;&#x526F;&#x672C;&#x8FDB;&#x884C;&#x7F29;&#x5BB9;&#xFF1B;</li>
</ol>
<pre class="language-"><code class="lang-go">minAvailable <span class="token operator">=</span> deployment<span class="token punctuation">.</span>Spec<span class="token punctuation">.</span>Replicas <span class="token operator">-</span> <span class="token function">maxUnavailable</span><span class="token punctuation">(</span>deployment<span class="token punctuation">)</span>
maxScaledDown <span class="token operator">=</span> allPodsCount <span class="token operator">-</span> minAvailable <span class="token operator">-</span> newReplicaSetPodsUnavailable
</code></pre>
<p>Go</p>
<p>&#x8BE5;&#x65B9;&#x6CD5;&#x4F1A;&#x4F7F;&#x7528;&#x4E0A;&#x8FF0;&#x7B80;&#x5316;&#x540E;&#x7684;&#x516C;&#x5F0F;&#x8BA1;&#x7B97;&#x8FD9;&#x6B21;&#x603B;&#x5171;&#x80FD;&#x591F;&#x5728;&#x5386;&#x53F2; ReplicaSet &#x4E2D;&#x5220;&#x9664;&#x7684;&#x6700;&#x5927; Pod &#x6570;&#x91CF;&#xFF0C;&#x5E76;&#x8C03;&#x7528; <code>cleanupUnhealthyReplicas</code> &#x548C; <code>scaleDownOldReplicaSetsForRollingUpdate</code> &#x4E24;&#x4E2A;&#x65B9;&#x6CD5;&#x8FDB;&#x884C;&#x7F29;&#x5BB9;&#xFF0C;&#x8FD9;&#x4E24;&#x4E2A;&#x65B9;&#x6CD5;&#x7684;&#x5B9E;&#x73B0;&#x90FD;&#x76F8;&#x5BF9;&#x7B80;&#x5355;&#xFF0C;&#x5B83;&#x4EEC;&#x90FD;&#x5BF9;&#x5386;&#x53F2; ReplicaSet &#x6309;&#x7167;&#x521B;&#x5EFA;&#x65F6;&#x95F4;&#x8FDB;&#x884C;&#x6392;&#x5E8F;&#x4F9D;&#x6B21;&#x5BF9;&#x8FD9;&#x4E9B;&#x8D44;&#x6E90;&#x8FDB;&#x884C;&#x7F29;&#x5BB9;&#xFF0C;&#x4E24;&#x8005;&#x7684;&#x533A;&#x522B;&#x5728;&#x4E8E;&#x524D;&#x8005;&#x4E3B;&#x8981;&#x7528;&#x4E8E;&#x5220;&#x9664;&#x4E0D;&#x5065;&#x5EB7;&#x7684;&#x526F;&#x672C;&#x3002;</p>
<h3 id="&#x56DE;&#x6EDA;"><a name="&#x56DE;&#x6EDA;" class="anchor-navigation-ex-anchor" href="#&#x56DE;&#x6EDA;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x56DE;&#x6EDA;</h3>
<p>Kubernetes &#x4E2D;&#x7684;&#x6BCF;&#x4E00;&#x4E2A; Deployment &#x8D44;&#x6E90;&#x90FD;&#x5305;&#x542B;&#x6709; <code>revision</code> &#x8FD9;&#x4E2A;&#x6982;&#x5FF5;&#xFF0C;&#x7248;&#x672C;&#x7684;&#x5F15;&#x5165;&#x53EF;&#x4EE5;&#x8BA9;&#x6211;&#x4EEC;&#x5728;&#x66F4;&#x65B0;&#x53D1;&#x751F;&#x95EE;&#x9898;&#x65F6;&#x53CA;&#x65F6;&#x901A;&#x8FC7; Deployment &#x7684;&#x7248;&#x672C;&#x5BF9;&#x5176;&#x8FDB;&#x884C;&#x56DE;&#x6EDA;&#xFF0C;&#x5F53;&#x6211;&#x4EEC;&#x5728;&#x66F4;&#x65B0; Deployment &#x65F6;&#xFF0C;&#x4E4B;&#x524D; Deployment &#x6301;&#x6709;&#x7684; ReplicaSet &#x5176;&#x5B9E;&#x4F1A;&#x88AB; <code>cleanupDeployment</code> &#x65B9;&#x6CD5;&#x6E05;&#x7406;&#xFF1A;</p>
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>dc <span class="token operator">*</span>DeploymentController<span class="token punctuation">)</span> <span class="token function">cleanupDeployment</span><span class="token punctuation">(</span>oldRSs <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token operator">*</span>apps<span class="token punctuation">.</span>ReplicaSet<span class="token punctuation">,</span> deployment <span class="token operator">*</span>apps<span class="token punctuation">.</span>Deployment<span class="token punctuation">)</span> <span class="token builtin">error</span> <span class="token punctuation">{</span>
    aliveFilter <span class="token operator">:=</span> <span class="token keyword">func</span><span class="token punctuation">(</span>rs <span class="token operator">*</span>apps<span class="token punctuation">.</span>ReplicaSet<span class="token punctuation">)</span> <span class="token builtin">bool</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> rs <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token operator">&amp;&amp;</span> rs<span class="token punctuation">.</span>ObjectMeta<span class="token punctuation">.</span>DeletionTimestamp <span class="token operator">==</span> <span class="token boolean">nil</span>
    <span class="token punctuation">}</span>
    cleanableRSes <span class="token operator">:=</span> controller<span class="token punctuation">.</span><span class="token function">FilterReplicaSets</span><span class="token punctuation">(</span>oldRSs<span class="token punctuation">,</span> aliveFilter<span class="token punctuation">)</span>

    diff <span class="token operator">:=</span> <span class="token function">int32</span><span class="token punctuation">(</span><span class="token function">len</span><span class="token punctuation">(</span>cleanableRSes<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token operator">-</span> <span class="token operator">*</span>deployment<span class="token punctuation">.</span>Spec<span class="token punctuation">.</span>RevisionHistoryLimit
    <span class="token keyword">if</span> diff <span class="token operator">&lt;=</span> <span class="token number">0</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token boolean">nil</span>
    <span class="token punctuation">}</span>
    sort<span class="token punctuation">.</span><span class="token function">Sort</span><span class="token punctuation">(</span>controller<span class="token punctuation">.</span><span class="token function">ReplicaSetsByCreationTimestamp</span><span class="token punctuation">(</span>cleanableRSes<span class="token punctuation">)</span><span class="token punctuation">)</span>

    <span class="token keyword">for</span> i <span class="token operator">:=</span> <span class="token function">int32</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> diff<span class="token punctuation">;</span> i<span class="token operator">++</span> <span class="token punctuation">{</span>
        rs <span class="token operator">:=</span> cleanableRSes<span class="token punctuation">[</span>i<span class="token punctuation">]</span>
        <span class="token keyword">if</span> rs<span class="token punctuation">.</span>Status<span class="token punctuation">.</span>Replicas <span class="token operator">!=</span> <span class="token number">0</span> <span class="token operator">||</span> <span class="token operator">*</span><span class="token punctuation">(</span>rs<span class="token punctuation">.</span>Spec<span class="token punctuation">.</span>Replicas<span class="token punctuation">)</span> <span class="token operator">!=</span> <span class="token number">0</span> <span class="token operator">||</span> rs<span class="token punctuation">.</span>Generation <span class="token operator">&gt;</span> rs<span class="token punctuation">.</span>Status<span class="token punctuation">.</span>ObservedGeneration <span class="token operator">||</span> rs<span class="token punctuation">.</span>DeletionTimestamp <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
            <span class="token keyword">continue</span>
        <span class="token punctuation">}</span>
        dc<span class="token punctuation">.</span>client<span class="token punctuation">.</span><span class="token function">AppsV1</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">ReplicaSets</span><span class="token punctuation">(</span>rs<span class="token punctuation">.</span>Namespace<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">Delete</span><span class="token punctuation">(</span>rs<span class="token punctuation">.</span>Name<span class="token punctuation">,</span> <span class="token boolean">nil</span><span class="token punctuation">)</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">return</span> <span class="token boolean">nil</span>
<span class="token punctuation">}</span>
</code></pre>
<p>Go</p>
<p>Deployment &#x8D44;&#x6E90;&#x5728;&#x89C4;&#x683C;&#x4E2D;&#x7531;&#x4E00;&#x4E2A; <code>spec.revisionHistoryLimit</code> &#x7684;&#x914D;&#x7F6E;&#xFF0C;&#x8FD9;&#x4E2A;&#x914D;&#x7F6E;&#x51B3;&#x5B9A;&#x4E86; Kubernetes &#x4F1A;&#x4FDD;&#x5B58;&#x591A;&#x5C11;&#x4E2A; ReplicaSet &#x7684;&#x5386;&#x53F2;&#x7248;&#x672C;&#xFF0C;&#x8FD9;&#x4E9B;&#x5386;&#x53F2;&#x4E0A;&#x7684; ReplicaSet &#x5E76;&#x4E0D;&#x4F1A;&#x88AB;&#x5220;&#x9664;&#xFF0C;&#x5B83;&#x4EEC;&#x53EA;&#x662F;&#x4E0D;&#x518D;&#x6301;&#x6709;&#x4EFB;&#x4F55;&#x7684; Pod &#x526F;&#x672C;&#x4E86;&#xFF0C;&#x5047;&#x8BBE;&#x6211;&#x4EEC;&#x6709;&#x4E00;&#x4E2A; <code>spec.revisionHistoryLimit=2</code> &#x7684; Deployment &#x5BF9;&#x8C61;&#xFF0C;&#x90A3;&#x4E48;&#x5F53;&#x524D;&#x8D44;&#x6E90;&#x6700;&#x591A;&#x6301;&#x6709;&#x4E24;&#x4E2A;&#x5386;&#x53F2;&#x7684; ReplicaSet &#x7248;&#x672C;&#xFF1A;</p>
<p><img src="https://img.draveness.me/2019-02-24-kubernetes-deployment-revision.png" alt="kubernetes-deployment-revision"></p>
<p>&#x8FD9;&#x4E9B;&#x8D44;&#x6E90;&#x7684;&#x4FDD;&#x7559;&#x80FD;&#x591F;&#x65B9;&#x4FBF; Deployment &#x7684;&#x56DE;&#x6EDA;&#xFF0C;&#x800C;&#x56DE;&#x6EDA;&#x5176;&#x5B9E;&#x662F;&#x901A;&#x8FC7; kubectl &#x5728;&#x5BA2;&#x6237;&#x7AEF;&#x5B9E;&#x73B0;&#x7684;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x5982;&#x4E0B;&#x7684;&#x547D;&#x4EE4;&#x5C06; Deployment &#x56DE;&#x6EDA;&#x5230;&#x4E0A;&#x4E00;&#x4E2A;&#x7248;&#x672C;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">$ kubectl rollout undo deployment.v1.apps/nginx-deployment
deployment.apps/nginx-deployment
</code></pre>
<p>Bash</p>
<p>&#x4E0A;&#x8FF0; kubectl &#x547D;&#x4EE4;&#x6CA1;&#x6709;&#x6307;&#x5B9A;&#x56DE;&#x6EDA;&#x5230;&#x7684;&#x7248;&#x672C;&#x53F7;&#xFF0C;&#x6240;&#x4EE5;&#x5728;&#x9ED8;&#x8BA4;&#x60C5;&#x51B5;&#x4E0B;&#x4F1A;&#x56DE;&#x6EDA;&#x5230;&#x4E0A;&#x4E00;&#x4E2A;&#x7248;&#x672C;&#xFF0C;&#x5728;&#x56DE;&#x6EDA;&#x65F6;&#x4F1A;&#x76F4;&#x63A5;&#x6839;&#x636E;&#x4F20;&#x5165;&#x7684;&#x7248;&#x672C;&#x67E5;&#x627E;&#x5386;&#x53F2;&#x7684; ReplicaSet &#x8D44;&#x6E90;&#xFF0C;&#x62FF;&#x5230;&#x8FD9;&#x4E2A; ReplicaSet &#x5BF9;&#x5E94;&#x7684; Pod &#x6A21;&#x677F;&#x540E;&#x4F1A;&#x89E6;&#x53D1;&#x4E00;&#x4E2A;&#x8D44;&#x6E90;&#x66F4;&#x65B0;&#x7684;&#x8BF7;&#x6C42;&#xFF1A;</p>
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>r <span class="token operator">*</span>DeploymentRollbacker<span class="token punctuation">)</span> <span class="token function">Rollback</span><span class="token punctuation">(</span>obj runtime<span class="token punctuation">.</span>Object<span class="token punctuation">,</span> updatedAnnotations <span class="token keyword">map</span><span class="token punctuation">[</span><span class="token builtin">string</span><span class="token punctuation">]</span><span class="token builtin">string</span><span class="token punctuation">,</span> toRevision <span class="token builtin">int64</span><span class="token punctuation">,</span> dryRun <span class="token builtin">bool</span><span class="token punctuation">)</span> <span class="token punctuation">(</span><span class="token builtin">string</span><span class="token punctuation">,</span> <span class="token builtin">error</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    accessor<span class="token punctuation">,</span> <span class="token boolean">_</span> <span class="token operator">:=</span> meta<span class="token punctuation">.</span><span class="token function">Accessor</span><span class="token punctuation">(</span>obj<span class="token punctuation">)</span>
    name <span class="token operator">:=</span> accessor<span class="token punctuation">.</span><span class="token function">GetName</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    namespace <span class="token operator">:=</span> accessor<span class="token punctuation">.</span><span class="token function">GetNamespace</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

    deployment<span class="token punctuation">,</span> <span class="token boolean">_</span> <span class="token operator">:=</span> r<span class="token punctuation">.</span>c<span class="token punctuation">.</span><span class="token function">AppsV1</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">Deployments</span><span class="token punctuation">(</span>namespace<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">Get</span><span class="token punctuation">(</span>name<span class="token punctuation">,</span> metav1<span class="token punctuation">.</span>GetOptions<span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span>
    rsForRevision<span class="token punctuation">,</span> <span class="token boolean">_</span> <span class="token operator">:=</span> <span class="token function">deploymentRevision</span><span class="token punctuation">(</span>deployment<span class="token punctuation">,</span> r<span class="token punctuation">.</span>c<span class="token punctuation">,</span> toRevision<span class="token punctuation">)</span>

    annotations <span class="token operator">:=</span> <span class="token operator">...</span>
    patchType<span class="token punctuation">,</span> patch<span class="token punctuation">,</span> <span class="token boolean">_</span> <span class="token operator">:=</span> <span class="token function">getDeploymentPatch</span><span class="token punctuation">(</span><span class="token operator">&amp;</span>rsForRevision<span class="token punctuation">.</span>Spec<span class="token punctuation">.</span>Template<span class="token punctuation">,</span> annotations<span class="token punctuation">)</span>

    r<span class="token punctuation">.</span>c<span class="token punctuation">.</span><span class="token function">AppsV1</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">Deployments</span><span class="token punctuation">(</span>namespace<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">Patch</span><span class="token punctuation">(</span>name<span class="token punctuation">,</span> patchType<span class="token punctuation">,</span> patch<span class="token punctuation">)</span>
    <span class="token keyword">return</span> rollbackSuccess<span class="token punctuation">,</span> <span class="token boolean">nil</span>
<span class="token punctuation">}</span>
</code></pre>
<p>Go</p>
<p>&#x56DE;&#x6EDA;&#x5BF9;&#x4E8E; Kubernetes &#x670D;&#x52A1;&#x7AEF;&#x6765;&#x8BF4;&#x5176;&#x5B9E;&#x4E0E;&#x5176;&#x4ED6;&#x7684;&#x66F4;&#x65B0;&#x64CD;&#x4F5C;&#x6CA1;&#x6709;&#x592A;&#x591A;&#x7684;&#x533A;&#x522B;&#xFF0C;&#x5728;&#x6BCF;&#x6B21;&#x66F4;&#x65B0;&#x65F6;&#x90FD;&#x4F1A;&#x5728; <code>FindNewReplicaSet</code> &#x51FD;&#x6570;&#x4E2D;&#x6839;&#x636E; Deployment &#x7684; Pod &#x6A21;&#x677F;&#x5728;&#x5386;&#x53F2; ReplicaSet &#x4E2D;&#x67E5;&#x8BE2;&#x662F;&#x5426;&#x6709;&#x76F8;&#x540C;&#x7684; ReplicaSet &#x5B58;&#x5728;&#xFF1A;</p>
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token function">FindNewReplicaSet</span><span class="token punctuation">(</span>deployment <span class="token operator">*</span>apps<span class="token punctuation">.</span>Deployment<span class="token punctuation">,</span> rsList <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token operator">*</span>apps<span class="token punctuation">.</span>ReplicaSet<span class="token punctuation">)</span> <span class="token operator">*</span>apps<span class="token punctuation">.</span>ReplicaSet <span class="token punctuation">{</span>
    sort<span class="token punctuation">.</span><span class="token function">Sort</span><span class="token punctuation">(</span>controller<span class="token punctuation">.</span><span class="token function">ReplicaSetsByCreationTimestamp</span><span class="token punctuation">(</span>rsList<span class="token punctuation">)</span><span class="token punctuation">)</span>
    <span class="token keyword">for</span> i <span class="token operator">:=</span> <span class="token keyword">range</span> rsList <span class="token punctuation">{</span>
        <span class="token keyword">if</span> <span class="token function">EqualIgnoreHash</span><span class="token punctuation">(</span><span class="token operator">&amp;</span>rsList<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">.</span>Spec<span class="token punctuation">.</span>Template<span class="token punctuation">,</span> <span class="token operator">&amp;</span>deployment<span class="token punctuation">.</span>Spec<span class="token punctuation">.</span>Template<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">return</span> rsList<span class="token punctuation">[</span>i<span class="token punctuation">]</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">return</span> <span class="token boolean">nil</span>
<span class="token punctuation">}</span>
</code></pre>
<p>Go</p>
<p>&#x5982;&#x679C;&#x5B58;&#x5728;&#x89C4;&#x683C;&#x5B8C;&#x5168;&#x76F8;&#x540C;&#x7684; ReplicaSet&#xFF0C;&#x5C31;&#x4F1A;&#x4FDD;&#x7559;&#x8FD9;&#x4E2A; ReplicaSet &#x5386;&#x53F2;&#x4E0A;&#x4F7F;&#x7528;&#x7684;&#x7248;&#x672C;&#x53F7;&#x5E76;&#x5BF9;&#x8BE5; ReplicaSet &#x91CD;&#x65B0;&#x8FDB;&#x884C;&#x6269;&#x5BB9;&#x5E76;&#x5BF9;&#x6B63;&#x5728;&#x5DE5;&#x4F5C;&#x7684; ReplicaSet &#x8FDB;&#x884C;&#x7F29;&#x5BB9;&#x4EE5;&#x5B9E;&#x73B0;&#x96C6;&#x7FA4;&#x7684;&#x671F;&#x671B;&#x72B6;&#x6001;&#x3002;</p>
<pre class="language-"><code class="lang-bash">$ k describe deployments.apps nginx-deployment
Name:                   nginx-deployment
Namespace:              default
CreationTimestamp:      Thu, <span class="token number">21</span> Feb <span class="token number">2019</span> <span class="token number">10</span>:14:29 +0800
Labels:                 <span class="token assign-left variable">app</span><span class="token operator">=</span>nginx
Annotations:            deployment.kubernetes.io/revision: <span class="token number">11</span>
                        kubectl.kubernetes.io/last-applied-configuration:
                          <span class="token punctuation">{</span><span class="token string">&quot;apiVersion&quot;</span><span class="token builtin class-name">:</span><span class="token string">&quot;apps/v1&quot;</span>,<span class="token string">&quot;kind&quot;</span><span class="token builtin class-name">:</span><span class="token string">&quot;Deployment&quot;</span>,<span class="token string">&quot;metadata&quot;</span>:<span class="token punctuation">{</span><span class="token string">&quot;annotations&quot;</span>:<span class="token punctuation">{</span><span class="token punctuation">}</span>,<span class="token string">&quot;labels&quot;</span>:<span class="token punctuation">{</span><span class="token string">&quot;app&quot;</span><span class="token builtin class-name">:</span><span class="token string">&quot;nginx&quot;</span><span class="token punctuation">}</span>,<span class="token string">&quot;name&quot;</span><span class="token builtin class-name">:</span><span class="token string">&quot;nginx-deployment&quot;</span>,<span class="token string">&quot;namespace&quot;</span>:&quot;d<span class="token punctuation">..</span>.
Selector:               <span class="token assign-left variable">app</span><span class="token operator">=</span>nginx
Replicas:               <span class="token number">3</span> desired <span class="token operator">|</span> <span class="token number">3</span> updated <span class="token operator">|</span> <span class="token number">3</span> total <span class="token operator">|</span> <span class="token number">3</span> available <span class="token operator">|</span> <span class="token number">0</span> unavailable
StrategyType:           RollingUpdate
<span class="token punctuation">..</span>.
Events:
  Type    Reason              Age   From                   Message
  ----    ------              ----  ----                   -------
  Normal  ScalingReplicaSet   20s   deployment-controller  Scaled up replica <span class="token builtin class-name">set</span> nginx-deployment-5cc74f885d to <span class="token number">1</span>
  Normal  ScalingReplicaSet   19s   deployment-controller  Scaled down replica <span class="token builtin class-name">set</span> nginx-deployment-7c6cf994f6 to <span class="token number">2</span>
  Normal  ScalingReplicaSet   19s   deployment-controller  Scaled up replica <span class="token builtin class-name">set</span> nginx-deployment-5cc74f885d to <span class="token number">2</span>
  Normal  ScalingReplicaSet   17s   deployment-controller  Scaled down replica <span class="token builtin class-name">set</span> nginx-deployment-7c6cf994f6 to <span class="token number">1</span>
  Normal  ScalingReplicaSet   17s   deployment-controller  Scaled up replica <span class="token builtin class-name">set</span> nginx-deployment-5cc74f885d to <span class="token number">3</span>
  Normal  ScalingReplicaSet   14s   deployment-controller  Scaled down replica <span class="token builtin class-name">set</span> nginx-deployment-7c6cf994f6 to <span class="token number">0</span>
</code></pre>
<p>Bash</p>
<p>&#x5728;&#x4E4B;&#x524D;&#x7684; Kubernetes &#x7248;&#x672C;&#x4E2D;&#xFF0C;&#x5BA2;&#x6237;&#x7AEF;&#x8FD8;&#x4F1A;&#x4F7F;&#x7528;&#x6CE8;&#x89E3;&#x6765;&#x5B9E;&#x73B0; Deployment &#x7684;&#x56DE;&#x6EDA;&#xFF0C;&#x4F46;&#x662F;&#x5728;&#x6700;&#x65B0;&#x7684; kubectl &#x7248;&#x672C;&#x4E2D;&#x8FD9;&#x79CD;&#x4F7F;&#x7528;&#x6CE8;&#x89E3;&#x7684;&#x65B9;&#x5F0F;&#x5DF2;&#x7ECF;&#x88AB;&#x5E9F;&#x5F03;&#x4E86;&#x3002;</p>
<h3 id="&#x6682;&#x505C;&#x548C;&#x6062;&#x590D;"><a name="&#x6682;&#x505C;&#x548C;&#x6062;&#x590D;" class="anchor-navigation-ex-anchor" href="#&#x6682;&#x505C;&#x548C;&#x6062;&#x590D;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x6682;&#x505C;&#x548C;&#x6062;&#x590D;</h3>
<p>Deployment &#x4E2D;&#x6709;&#x4E00;&#x4E2A;&#x4E0D;&#x662F;&#x7279;&#x522B;&#x5E38;&#x7528;&#x7684;&#x529F;&#x80FD;&#xFF0C;&#x4E5F;&#x5C31;&#x662F; Deployment &#x8FDB;&#x884C;&#x6682;&#x505C;&#xFF0C;&#x6682;&#x505C;&#x4E4B;&#x540E;&#x7684; Deployment &#x54EA;&#x6015;&#x53D1;&#x751F;&#x4E86;&#x6539;&#x52A8;&#x4E5F;&#x4E0D;&#x4F1A;&#x88AB; Kubernetes &#x66F4;&#x65B0;&#xFF0C;&#x8FD9;&#x65F6;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5BF9; Deployment &#x8D44;&#x6E90;&#x8FDB;&#x884C;&#x66F4;&#x65B0;&#x6216;&#x8005;&#x4FEE;&#x590D;&#xFF0C;&#x968F;&#x540E;&#x5F53;&#x91CD;&#x65B0;&#x6062;&#x590D; Deployment &#x65F6;&#xFF0C;<code>DeploymentController</code> &#x624D;&#x4F1A;&#x91CD;&#x65B0;&#x5BF9;&#x5176;&#x8FDB;&#x884C;&#x6EDA;&#x52A8;&#x66F4;&#x65B0;&#x5411;&#x671F;&#x671B;&#x72B6;&#x6001;&#x8FC1;&#x79FB;&#xFF1A;</p>
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token function">defaultObjectPauser</span><span class="token punctuation">(</span>obj runtime<span class="token punctuation">.</span>Object<span class="token punctuation">)</span> <span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token builtin">byte</span><span class="token punctuation">,</span> <span class="token builtin">error</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">switch</span> obj <span class="token operator">:=</span> obj<span class="token punctuation">.</span><span class="token punctuation">(</span><span class="token keyword">type</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">case</span> <span class="token operator">*</span>appsv1<span class="token punctuation">.</span>Deployment<span class="token punctuation">:</span>
        <span class="token keyword">if</span> obj<span class="token punctuation">.</span>Spec<span class="token punctuation">.</span>Paused <span class="token punctuation">{</span>
            <span class="token keyword">return</span> <span class="token boolean">nil</span><span class="token punctuation">,</span> errors<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">&quot;is already paused&quot;</span><span class="token punctuation">)</span>
        <span class="token punctuation">}</span>
        obj<span class="token punctuation">.</span>Spec<span class="token punctuation">.</span>Paused <span class="token operator">=</span> <span class="token boolean">true</span>
        <span class="token keyword">return</span> runtime<span class="token punctuation">.</span><span class="token function">Encode</span><span class="token punctuation">(</span>scheme<span class="token punctuation">.</span>Codecs<span class="token punctuation">.</span><span class="token function">LegacyCodec</span><span class="token punctuation">(</span>appsv1<span class="token punctuation">.</span>SchemeGroupVersion<span class="token punctuation">)</span><span class="token punctuation">,</span> obj<span class="token punctuation">)</span>

    <span class="token comment">// ...</span>
    <span class="token keyword">default</span><span class="token punctuation">:</span>
        <span class="token keyword">return</span> <span class="token boolean">nil</span><span class="token punctuation">,</span> fmt<span class="token punctuation">.</span><span class="token function">Errorf</span><span class="token punctuation">(</span><span class="token string">&quot;pausing is not supported&quot;</span><span class="token punctuation">)</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>Go</p>
<p>&#x6682;&#x505C;&#x548C;&#x6062;&#x590D;&#x4E5F;&#x90FD;&#x662F;&#x7531; kubectl &#x5728;&#x5BA2;&#x6237;&#x7AEF;&#x5B9E;&#x73B0;&#x7684;&#xFF0C;&#x5176;&#x5B9E;&#x5C31;&#x662F;&#x901A;&#x8FC7;&#x66F4;&#x6539; <code>spec.paused</code> &#x5C5E;&#x6027;&#xFF0C;&#x8FD9;&#x91CC;&#x7684;&#x66F4;&#x6539;&#x4F1A;&#x53D8;&#x6210;&#x4E00;&#x4E2A;&#x66F4;&#x65B0;&#x64CD;&#x4F5C;&#x4FEE;&#x6539; Deployment &#x8D44;&#x6E90;&#x3002;</p>
<pre class="language-"><code class="lang-bash">$ kubectl rollout pause deployment.v1.apps/nginx-deployment
deployment.apps/nginx-deployment paused

$ kubectl get deployments.apps nginx-deployment -o yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  <span class="token comment"># ...</span>
  name: nginx-deployment
  namespace: default
  selfLink: /apis/apps/v1/namespaces/default/deployments/nginx-deployment
  uid: 6b44965f-357e-11e9-af24-0800275e8310
spec:
  paused: <span class="token boolean">true</span>
  <span class="token comment"># ...</span>
</code></pre>
<p>Bash</p>
<p>&#x5982;&#x679C;&#x6211;&#x4EEC;&#x4F7F;&#x7528; YAML &#x6587;&#x4EF6;&#x548C; <code>kubectl apply</code> &#x547D;&#x4EE4;&#x6765;&#x66F4;&#x65B0;&#x6574;&#x4E2A; Deployment &#x8D44;&#x6E90;&#xFF0C;&#x90A3;&#x4E48;&#x5176;&#x5B9E;&#x7528;&#x4E0D;&#x5230;&#x6682;&#x505C;&#x8FD9;&#x4E00;&#x529F;&#x80FD;&#xFF0C;&#x6211;&#x4EEC;&#x53EA;&#x9700;&#x8981;&#x5728;&#x6587;&#x4EF6;&#x91CC;&#x5BF9;&#x8D44;&#x6E90;&#x8FDB;&#x884C;&#x4FEE;&#x6539;&#x5E76;&#x8FDB;&#x884C;&#x4E00;&#x6B21;&#x66F4;&#x65B0;&#x5C31;&#x53EF;&#x4EE5;&#x4E86;&#xFF0C;&#x4F46;&#x662F;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5728;&#x51FA;&#x73B0;&#x95EE;&#x9898;&#x65F6;&#xFF0C;&#x6682;&#x505C;&#x4E00;&#x6B21;&#x6B63;&#x5728;&#x8FDB;&#x884C;&#x7684;&#x6EDA;&#x52A8;&#x66F4;&#x65B0;&#x4EE5;&#x9632;&#x6B62;&#x9519;&#x8BEF;&#x7684;&#x6269;&#x6563;&#x3002;</p>
<h3 id="&#x5220;&#x9664;"><a name="&#x5220;&#x9664;" class="anchor-navigation-ex-anchor" href="#&#x5220;&#x9664;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5220;&#x9664;</h3>
<p>&#x5982;&#x679C;&#x6211;&#x4EEC;&#x5728; Kubernetes &#x96C6;&#x7FA4;&#x4E2D;&#x5220;&#x9664;&#x4E86;&#x4E00;&#x4E2A; Deployment &#x8D44;&#x6E90;&#xFF0C;&#x90A3;&#x4E48; Deployment &#x6301;&#x6709;&#x7684; ReplicaSet &#x4EE5;&#x53CA; ReplicaSet &#x6301;&#x6709;&#x7684;&#x526F;&#x672C;&#x90FD;&#x4F1A;&#x88AB; Kubernetes &#x4E2D;&#x7684; <a href="https://draveness.me/kubernetes-garbage-collector" target="_blank">&#x5783;&#x573E;&#x6536;&#x96C6;&#x5668;</a> &#x5220;&#x9664;&#xFF1A;</p>
<pre class="language-"><code class="lang-go">$ kubectl <span class="token builtin">delete</span> deployments<span class="token punctuation">.</span>apps nginx<span class="token operator">-</span>deployment
deployment<span class="token punctuation">.</span>apps <span class="token string">&quot;nginx-deployment&quot;</span> deleted

$ kubectl get replicasets <span class="token operator">--</span>watch
nginx<span class="token operator">-</span>deployment<span class="token operator">-</span><span class="token number">7</span>c6cf994f6   <span class="token number">0</span>     <span class="token number">0</span>     <span class="token number">0</span>     <span class="token number">2</span>d1h
nginx<span class="token operator">-</span>deployment<span class="token operator">-</span><span class="token number">5</span>cc74f885d   <span class="token number">0</span>     <span class="token number">0</span>     <span class="token number">0</span>     <span class="token number">2</span>d1h
nginx<span class="token operator">-</span>deployment<span class="token operator">-</span>c5d875444   <span class="token number">3</span>     <span class="token number">3</span>     <span class="token number">3</span>     <span class="token number">30</span>h

$ kubectl get pods <span class="token operator">--</span>watch
nginx<span class="token operator">-</span>deployment<span class="token operator">-</span>c5d875444<span class="token operator">-</span><span class="token number">6</span>r4q6   <span class="token number">1</span><span class="token operator">/</span><span class="token number">1</span>   Terminating   <span class="token number">2</span>     <span class="token number">30</span>h
nginx<span class="token operator">-</span>deployment<span class="token operator">-</span>c5d875444<span class="token operator">-</span><span class="token number">7</span>ssgj   <span class="token number">1</span><span class="token operator">/</span><span class="token number">1</span>   Terminating   <span class="token number">2</span>     <span class="token number">30</span>h
nginx<span class="token operator">-</span>deployment<span class="token operator">-</span>c5d875444<span class="token operator">-</span><span class="token number">4</span>xvvz   <span class="token number">1</span><span class="token operator">/</span><span class="token number">1</span>   Terminating   <span class="token number">2</span>     <span class="token number">30</span>h
</code></pre>
<p>Go</p>
<p>&#x7531;&#x4E8E;&#x4E0E;&#x5F53;&#x524D; Deployment &#x6709;&#x5173;&#x7684; ReplicaSet &#x5386;&#x53F2;&#x548C;&#x6700;&#x65B0;&#x7248;&#x672C;&#x90FD;&#x4F1A;&#x88AB;&#x5220;&#x9664;&#xFF0C;&#x6240;&#x4EE5;&#x5BF9;&#x5E94;&#x7684; Pod &#x526F;&#x672C;&#x4E5F;&#x90FD;&#x4F1A;&#x968F;&#x4E4B;&#x88AB;&#x5220;&#x9664;&#xFF0C;&#x8FD9;&#x4E9B;&#x5BF9;&#x8C61;&#x4E4B;&#x95F4;&#x7684;&#x5173;&#x7CFB;&#x90FD;&#x662F;&#x901A;&#x8FC7; <code>metadata.ownerReference</code> &#x8FD9;&#x4E00;&#x5B57;&#x6BB5;&#x5173;&#x8054;&#x7684;&#xFF0C;<a href="https://draveness.me/kubernetes-garbage-collector" target="_blank">&#x5783;&#x573E;&#x6536;&#x96C6;&#x5668;</a> &#x4E00;&#x8282;&#x8BE6;&#x7EC6;&#x4ECB;&#x7ECD;&#x4E86;&#x5B83;&#x7684;&#x5B9E;&#x73B0;&#x539F;&#x7406;&#x3002;</p>
<h2 id="&#x603B;&#x7ED3;"><a name="&#x603B;&#x7ED3;" class="anchor-navigation-ex-anchor" href="#&#x603B;&#x7ED3;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x603B;&#x7ED3;</h2>
<p>Deployment &#x662F; Kubernetes &#x4E2D;&#x5E38;&#x7528;&#x7684;&#x5BF9;&#x8C61;&#x7C7B;&#x578B;&#xFF0C;&#x5B83;&#x89E3;&#x51B3;&#x4E86; ReplicaSet &#x66F4;&#x65B0;&#x7684;&#x8BF8;&#x591A;&#x95EE;&#x9898;&#xFF0C;&#x901A;&#x8FC7;&#x5BF9; ReplicaSet &#x548C; Pod &#x8FDB;&#x884C;&#x7EC4;&#x88C5;&#x652F;&#x6301;&#x4E86;&#x6EDA;&#x52A8;&#x66F4;&#x65B0;&#x3001;&#x56DE;&#x6EDA;&#x4EE5;&#x53CA;&#x6269;&#x5BB9;&#x7B49;&#x9AD8;&#x7EA7;&#x529F;&#x80FD;&#xFF0C;&#x901A;&#x8FC7;&#x5BF9; Deployment &#x7684;&#x5B66;&#x4E60;&#x65E2;&#x80FD;&#x8BA9;&#x6211;&#x4EEC;&#x4E86;&#x89E3;&#x6574;&#x4E2A;&#x5E38;&#x89C1;&#x8D44;&#x6E90;&#x7684;&#x5B9E;&#x73B0;&#x4E5F;&#x80FD;&#x5E2E;&#x52A9;&#x6211;&#x4EEC;&#x7406;&#x89E3;&#x5982;&#x4F55;&#x5C06; Kubernetes &#x5185;&#x7F6E;&#x7684;&#x5BF9;&#x8C61;&#x7EC4;&#x5408;&#x6210;&#x66F4;&#x590D;&#x6742;&#x7684;&#x81EA;&#x5B9A;&#x4E49;&#x8D44;&#x6E90;&#x3002; </p>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; caixisheng 2017 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x8BE5;&#x6587;&#x4EF6;&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;&#xFF1A;
2021-05-19 10:00:31
</span></footer> <link rel="stylesheet" type="text/css" href="https://storage.googleapis.com/app.klipse.tech/css/codemirror.css"> <script>     window.klipse_settings = {         selector: ".language-klipse, .lang-eval-clojure",         selector_eval_js: ".lang-eval-js",         selector_eval_python_client: ".lang-eval-python",         selector_eval_php: ".lang-eval-php",         selector_eval_scheme: ".lang-eval-scheme",         selector_eval_ruby: ".lang-eval-ruby",         selector_reagent: ".lang-reagent",        selector_google_charts: ".lang-google-chart",        selector_es2017: ".lang-eval-es2017",        selector_jsx: ".lang-eval-jsx",        selector_transpile_jsx: ".lang-transpile-jsx",        selector_render_jsx: ".lang-render-jsx",        selector_react: ".lang-react",        selector_eval_markdown: ".lang-render-markdown",        selector_eval_lambdaway: ".lang-render-lambdaway",        selector_eval_cpp: ".lang-eval-cpp",        selector_eval_html: ".lang-render-html",        selector_sql: ".lang-eval-sql",        selector_brainfuck: "lang-eval-brainfuck",        selector_js: ".lang-transpile-cljs"    }; </script> <script src="https://storage.googleapis.com/app.klipse.tech/plugin/js/klipse_plugin.js"></script>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="CAK.html" class="navigation navigation-prev " aria-label="Previous page: CAK">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="K8s源码/" class="navigation navigation-next " aria-label="Next page: K8s源码">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Deployment 的实现原理","level":"1.9.3","depth":2,"next":{"title":"K8s源码","level":"1.9.4","depth":2,"path":"blog/kubernetes/K8s源码/README.md","ref":"blog/kubernetes/K8s源码/README.md","articles":[{"title":"Calico 源码分析","level":"1.9.4.1","depth":3,"path":"blog/kubernetes/K8s源码/calico 源码分析.md","ref":"blog/kubernetes/K8s源码/calico 源码分析.md","articles":[]},{"title":"Garbage Collector Controller 源码分析","level":"1.9.4.2","depth":3,"path":"blog/kubernetes/K8s源码/garbage collector controller 源码分析.md","ref":"blog/kubernetes/K8s源码/garbage collector controller 源码分析.md","articles":[]},{"title":"Job","level":"1.9.4.3","depth":3,"path":"blog/kubernetes/K8s源码/job.md","ref":"blog/kubernetes/K8s源码/job.md","articles":[]},{"title":"Kube Proxy Iptables","level":"1.9.4.4","depth":3,"path":"blog/kubernetes/K8s源码/kube-proxy-iptables.md","ref":"blog/kubernetes/K8s源码/kube-proxy-iptables.md","articles":[]},{"title":"Kube Proxy Ipvs","level":"1.9.4.5","depth":3,"path":"blog/kubernetes/K8s源码/kube-proxy-ipvs.md","ref":"blog/kubernetes/K8s源码/kube-proxy-ipvs.md","articles":[]},{"title":"Kube Proxy","level":"1.9.4.6","depth":3,"path":"blog/kubernetes/K8s源码/kube-proxy.md","ref":"blog/kubernetes/K8s源码/kube-proxy.md","articles":[]},{"title":"Kubectl Exec","level":"1.9.4.7","depth":3,"path":"blog/kubernetes/K8s源码/kubectl-exec.md","ref":"blog/kubernetes/K8s源码/kubectl-exec.md","articles":[]},{"title":"Kubectl源码阅读1","level":"1.9.4.8","depth":3,"path":"blog/kubernetes/K8s源码/kubectl源码阅读1.md","ref":"blog/kubernetes/K8s源码/kubectl源码阅读1.md","articles":[]},{"title":"Kubectl源码阅读2","level":"1.9.4.9","depth":3,"path":"blog/kubernetes/K8s源码/kubectl源码阅读2.md","ref":"blog/kubernetes/K8s源码/kubectl源码阅读2.md","articles":[]},{"title":"Readme","level":"1.9.4.10","depth":3,"path":"blog/kubernetes/K8s源码/readme.md","ref":"blog/kubernetes/K8s源码/readme.md","articles":[]},{"title":"Schedule","level":"1.9.4.11","depth":3,"path":"blog/kubernetes/K8s源码/schedule.md","ref":"blog/kubernetes/K8s源码/schedule.md","articles":[]},{"title":"Scheme","level":"1.9.4.12","depth":3,"path":"blog/kubernetes/K8s源码/scheme.md","ref":"blog/kubernetes/K8s源码/scheme.md","articles":[]},{"title":"调度队列","level":"1.9.4.13","depth":3,"path":"blog/kubernetes/K8s源码/调度队列.md","ref":"blog/kubernetes/K8s源码/调度队列.md","articles":[]}]},"previous":{"title":"CAK","level":"1.9.2","depth":2,"path":"blog/kubernetes/CAK.md","ref":"blog/kubernetes/CAK.md","articles":[]},"dir":"ltr"},"config":{"plugins":["summary","expandable-chapters","toggle-chapters","theme-comscore","-lunr","-search","-highlight","-livereload","search-plus@^0.0.11","simple-page-toc@^0.1.1","github@^2.0.0","github-buttons@2.1.0","edit-link@^2.0.2","disqus@^0.1.0","prism@^2.1.0","prism-themes@^0.0.2","advanced-emoji@^0.2.1","anchors@^0.7.1","include-codeblock@^3.0.2","emphasize@^1.1.0","katex@^1.1.3","splitter@^0.0.8","mermaid-gb3@2.1.0","tbfed-pagefooter@^0.0.1","expandable-chapters-small@^0.1.7","sectionx@^3.1.0","donate@^1.0.2","local-video@^1.0.1","anchor-navigation-ex@0.1.8","favicon@^0.0.2","3-ba@^0.9.0","terminal@^0.3.2","alerts@^0.2.0","include-csv@^0.1.0","puml@^1.0.1","musicxml@^1.0.2","klipse@^1.2.0","versions-select@^0.1.1","-sharing","sharing-plus@^0.0.2","graph@^0.1.0","chart@^0.2.0"],"root":".","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright © caixisheng 2017","modify_label":"该文件修订时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"prism":{"css":["prism-themes/themes/prism-base16-ateliersulphurpool.light.css"]},"include-csv":{},"disqus":{"useIdentifier":false,"shortName":"gitbookuse"},"emphasize":{},"github":{"url":"https://github.com/xishengcai/xisheng.blog"},"puml":{},"simple-page-toc":{"maxDepth":3,"skipFirstH1":true},"summary":{},"splitter":{},"sharing-plus":{"qq":false,"all":["facebook","google","twitter","instapaper","linkedin","pocket","stumbleupon"],"douban":false,"facebook":true,"weibo":false,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":true,"messenger":false,"line":false,"vk":false,"pocket":true,"google":false,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":false},"versions-select":{"type":"branches"},"graph":{},"donate":{"alipay":"https://cai-hello-1253732611.cos.ap-shanghai.myqcloud.com/share/zhifubao-pay.jpg","alipayText":"支付宝打赏","button":"赏","title":"","wechat":"https://cai-hello-1253732611.cos.ap-shanghai.myqcloud.com/share/weixin-pay.jpg","wechatText":"微信打赏"},"katex":{},"fontsettings":{"theme":"white","family":"sans","size":2},"musicxml":{},"sectionx":{"tag":"b"},"mermaid-gb3":{},"anchor-navigation-ex":{"isRewritePageTitle":false,"tocLevel1Icon":"fa fa-hand-o-right","tocLevel2Icon":"fa fa-hand-o-right","tocLevel3Icon":"fa fa-hand-o-right"},"favicon":{"shortcut":"favicon.ico","bookmark":"favicon.ico"},"theme-comscore":{},"prism-themes":{},"alerts":{},"github-buttons":{"repo":"xishengcai/xisheng.blog","types":["star"],"size":"small"},"3-ba":{"configuration":"auto","token":"ff100361cdce95dd4c8fb96b4009f7bc"},"expandable-chapters-small":{},"local-video":{},"klipse":{"myConfigKey":"it's the default value"},"advanced-emoji":{"embedEmojis":false},"include-codeblock":{"check":false,"edit":true,"fixlang":false,"lang":"","template":"ace","theme":"chrome","unindent":true},"sharing":{"qq":false,"all":["facebook","google","twitter","weibo","instapaper","linkedin","pocket","stumbleupon","qq","qzone"],"douban":false,"facebook":false,"weibo":true,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":false,"messenger":false,"line":false,"vk":false,"pocket":false,"google":true,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":true},"terminal":{"copyButtons":true,"fade":false,"style":"flat"},"edit-link":{"label":"Edit This Page","base":"https://github.com/xishengcai/xisheng.blog/edit/master"},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":true},"anchors":{},"chart":{"type":"c3"},"toggle-chapters":{},"expandable-chapters":{},"search-plus":{}},"theme":"default","author":"xishengcai","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"这是程序员吗","language":"zh-hans","output.name":"site","links":{"sidebar":{"Home":"https://xisheng.vip"}},"gitbook":"3.2.3","description":"这是程序员吗"},"file":{"path":"blog/kubernetes/Deployment 的实现原理.md","mtime":"2021-05-19T02:00:31.728Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-06-23T07:51:54.455Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-toggle-chapters/toggle.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-plus/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-plus/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-github/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-github-buttons/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-edit-link/plugin.js"></script>
        
    
        
        <script src="https://cdnjs.cloudflare.com/ajax/libs/URI.js/1.16.1/URI.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-disqus/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-mermaid-gb3/book/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.js"></script>
        
    
        
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sectionx/sectionx.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-donate/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-local-video/video.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-3-ba/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-terminal/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-alerts/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-musicxml/osmd.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-musicxml/musicxml.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-musicxml/promise.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-versions-select/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing-plus/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    <script src="../../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.min.js"></script>

    </body>
</html>

